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.09 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 ok = 1;
  27.         for(int i = 0; i < strlen(s); i++) {
  28.             if(isspace(s[i])) {
  29.                 if(tolower(zbor[0]) != tolower(zbor[j - 1])) {
  30.                     ok = -1;
  31.                     break;
  32.                 }
  33.                 j = 0;
  34.             }
  35.             else {
  36.                 zbor[j] = s[i];
  37.                 j++;
  38.             }
  39.         }
  40.         if(ok == 1) {
  41.             fprintf(out, "%s", s);
  42.         }
  43.     }
  44.     return 0;
  45. }
  46.  
  47.  
  48. /*
  49. 8
  50. 1 2 -1 -2 4 3 15  7  2
  51. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement