Advertisement
Josif_tepe

Untitled

Aug 25th, 2023
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6.  
  7. int main(int argc, const char * argv[]) {
  8.    
  9.     if(argc < 3) {
  10.         return 0;
  11.     }
  12.     FILE *in = fopen(argv[1], "r");
  13.     FILE *out = fopen(argv[2], "w");
  14.    
  15.     char zbor[1000];
  16.     int brojac = 0;
  17.     while(fscanf(in, "%s", zbor)) {
  18.         if(zbor[strlen(zbor) - 1] == '.' || zbor[strlen(zbor - 1)] == ',') {
  19.             int dali_e_palindrom = 1;
  20.             int i = 0;
  21.             int j = strlen(zbor) - 2;
  22.            
  23.             while(i < j) {
  24.                 if(zbor[i] == zbor[j]) {
  25.                     i++;
  26.                     j--;
  27.                 }
  28.                 else {
  29.                     dali_e_palindrom = 0;
  30.                     break;
  31.                 }
  32.             }
  33.             if(dali_e_palindrom) {
  34.                 for(int k = 0; k < strlen(zbor) - 1; k++) {
  35.                     fprintf(out, "%c", zbor[k]);
  36.                 }
  37.                 fprintf(out, "\n");
  38.                 brojac++;
  39.             }
  40.         }
  41.     }
  42.     fprintf(out, "%d\n", brojac);
  43.    
  44.    
  45.     return 0;
  46.    
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement