Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int palindrom2 ( char text[] )
- {
- int dlugosc,i,odp=0;
- char *ptr,*ptr2;
- ptr=text;
- ptr2=text+(strlen(text)-1);
- dlugosc=strlen(text)-1;
- for(i=0;i<dlugosc;i++)
- {
- while(*ptr==' ')
- {
- ptr++;
- }
- while(*ptr2==' ')
- {
- ptr2--;
- }
- if(tolower(*ptr)==tolower(*ptr2))
- {
- odp=1;
- }
- else
- {
- odp=0;
- break;
- }
- ptr++;
- ptr2--;
- }
- return odp;
- }
- int main(int argc, char *argv[])
- {
- char text[]="Zakopane na pokaz";
- if (palindrom2(text)==1)
- {
- printf("Zdanie '%s' jest palindromem", text);
- }
- else
- {
- printf("Zdanie '%s' nie jest palindromem", text);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement