Character Pointers and Case Sensitive when checking if a string is a
palindrome in C
my code here checks a string to see if it is a palindrome. However, it
doesn't check for uppercase letters and it also doesn't use character
pointers which I am supposed to use in this program. Can someone give me
some tips?
#include <stdio.h>
#include <string.h>
int main(){
char string1[20];
int i, length;
int flag = 0;
printf("Enter a string: ");
scanf("%s", string1);
length = strlen(string1);
for(i=0;i < length ;i++){
if((string1[i]) != (string1[length-i-1])){
flag = 1;
break;
}
}
if (flag)
printf("%s is not a palindrome \n\n", string1);
else
printf("%s is a palindrome \n", string1);
return 0;
}
No comments:
Post a Comment