Advertisement
nocturnalmk

lab8-3

Dec 20th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. // vrakja Segmentation fault greska
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. int palindrom(char *zbor) {
  8.  
  9.     int i = 0;
  10.     int dolz = strlen(zbor);
  11.  
  12.     for (i; i <= dolz/2; i++) {
  13.         if (zbor[i] != zbor[dolz-i-1]) {
  14.             return 0;
  15.         }
  16.     }
  17.  
  18.     return 1;
  19.  
  20. }
  21.  
  22. int main(int argc, char *argv[]) {
  23.  
  24.     char zbor[21];
  25.     FILE *s;
  26.     int i;
  27.     char c;
  28.  
  29.     s = fopen(argv[1], "r");
  30.  
  31.     if (s == NULL) {
  32.         printf("Greska so datotekata.");
  33.     } else {
  34.  
  35.         while (c = fgetc(s) != EOF) {
  36.  
  37.             if (isalpha(c)) {
  38.  
  39.                 zbor[i] = c;
  40.                 i++;
  41.  
  42.             } else {
  43.  
  44.                 zbor[i] = '\0';
  45.                 if (i > 1) {
  46.                     if (palindrom(zbor) == 1) {
  47.                         printf("%s\n", zbor);
  48.                     }
  49.                 }
  50.                 i = 0;
  51.  
  52.             }
  53.  
  54.         }
  55.  
  56.     }
  57.  
  58.     fclose(s);
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement