Advertisement
Guest User

z21b

a guest
Jun 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int palindrom2 ( char text[] )
  7. {
  8.     int dlugosc,i,odp=0;
  9.     char *ptr,*ptr2;
  10.     ptr=text;
  11.     ptr2=text+(strlen(text)-1);
  12.     dlugosc=strlen(text)-1;
  13.     for(i=0;i<dlugosc;i++)
  14.     {
  15.         while(*ptr==' ')
  16.         {
  17.             ptr++;
  18.         }
  19.         while(*ptr2==' ')
  20.         {
  21.             ptr2--;
  22.         }
  23.         if(tolower(*ptr)==tolower(*ptr2))
  24.         {
  25.             odp=1;
  26.         }
  27.         else
  28.         {
  29.             odp=0;
  30.             break;
  31.         }
  32.         ptr++;
  33.         ptr2--;
  34.     }
  35.     return odp;
  36. }
  37.  
  38. int main(int argc, char *argv[])
  39. {
  40.     char text[]="Zakopane na pokaz";
  41.     if (palindrom2(text)==1)
  42.     {
  43.         printf("Zdanie '%s' jest palindromem", text);
  44.     }
  45.     else
  46.     {
  47.         printf("Zdanie '%s' nie jest palindromem", text);
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement