Advertisement
Josif_tepe

Untitled

Jan 20th, 2024
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. int main(int argc, const char * argv[]) {
  8.     if(argc < 3) {
  9.         printf("Vlezna i izlezna se vnesuvaat kako argumenti\n");
  10.         return 0;
  11.     }    
  12.     FILE *in = fopen(argv[1], "r");
  13.     FILE *out = fopen(argv[2], "w");
  14.  
  15.     if(in == NULL) {
  16.         printf("Ne validna vlezna datoteka\n");
  17.         return 0;
  18.     }
  19.     if(out == NULL) {
  20.         printf("Ne validna izlezna datoteka\n");
  21.     }
  22.     char s[2000];
  23.     while(fgets(s, 1000, in) != NULL) {
  24.         char zbor[2000];
  25.         int j = 0;
  26.         int prv_zbor = -1;
  27.         char prva_bukva;
  28.         int ok = 1;
  29.         for(int i = 0; i < strlen(s); i++) {
  30.             if(isspace(s[i])) {
  31.                 if(prv_zbor == -1) {
  32.                     prva_bukva = tolower(zbor[0]);
  33.                 }
  34.                 else {
  35.                     if(prva_bukva != zbor[j - 1]) {
  36.                         ok = -1;
  37.                         break;
  38.                     }
  39.                 }
  40.                 prva_bukva = tolower(zbor[0]);
  41.                 j = 0;
  42.                 prv_zbor = 1;
  43.             }
  44.             else {
  45.                 zbor[j] = s[i];
  46.                 j++;
  47.             }
  48.         }
  49.         if(ok == 1) {
  50.             fprintf(out, "%s", s);
  51.         }
  52.     }
  53.     return 0;
  54. }
  55.  
  56.  
  57. /*
  58. 8
  59. 1 2 -1 -2 4 3 15  7  2
  60. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement