assignment-s-05.c (1010B)
1 /* Write a function to check whether a given string is a palindrome. Use this function to 2 determine whether an entered string is Palindrome. */ 3 4 #include <stdio.h> 5 #include <string.h> 6 7 int isPalindrome(char[]); 8 9 int main() 10 { 11 char input[100]; 12 int len; 13 14 printf("Enter the string (Max: 100 Character): "); 15 fgets(input, sizeof(input), stdin); 16 len = strlen(input); 17 18 if (len > 0 && input[len - 1] == '\n') 19 { 20 input[len - 1] = '\0'; 21 } 22 23 if (isPalindrome(input)) 24 { 25 printf("\nInput string \"%s\" is Palindrome.", input); 26 } 27 else 28 { 29 printf("\nInput string \"%s\" is not Palindrome", input); 30 } 31 32 return 0; 33 } 34 35 int isPalindrome(char str[]) 36 { 37 char *start = str; 38 char *end; 39 int len = strlen(str); 40 41 if (len == 0) 42 { 43 return 1; 44 } 45 46 end = str + (len - 1); 47 48 while (start < end) 49 { 50 if (*start != *end) 51 { 52 return 0; 53 } 54 start++; 55 end--; 56 } 57 58 return 1; 59 }