Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<ctype.h>
- #include<string.h>
- #include<stdbool.h>
- void RemoveChars(char *s, char c);
- main()
- {
- char str[50], *ptr, *p, *i, *j;
- bool is_palindrome=true;
- gets(str);
- RemoveChars(str, ' ');
- RemoveChars(str, '.');
- RemoveChars(str,'-');
- RemoveChars(str, '!');
- RemoveChars(str, '?');
- RemoveChars(str, ',');
- RemoveChars(str, ';');
- RemoveChars(str, ':');
- int n=strlen(str);
- for( p=str; p<str+n; p++)
- {
- *p=toupper(*p);
- }
- for( i=str, j=str+n-1; i<str+n, j>=str; i++, j--)
- {
- if(*i!=*j)
- {
- is_palindrome=false;
- }
- }
- if(is_palindrome)
- {
- printf("It is a palindrome");
- }
- else
- printf("It is not a palindrome");
- }
- void RemoveChars(char *s, char c)
- {
- int writer = 0, reader = 0;
- while (s[reader])
- {
- if (s[reader]!=c)
- {
- s[writer] = s[reader];
- writer++;
- }
- reader++;
- }
- s[writer]=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment