assignment-p-13.c (1061B)
1 /* Write a C program that accepts a string as a command line argument and includes a user- 2 defined function named isPalindrome with the signature int isPalindrome(char str[]);. 3 The function should check if the given string is a palindrome and return 1 if it is, and 0 4 otherwise. */ 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <string.h> 9 10 int isPalindrome(char[]); 11 12 int main(int argc, char *argv[]) 13 { 14 if (argc != 2) 15 { 16 printf("\nUsage: %s <string>\n", argv[0]); 17 return 1; 18 } 19 if (isPalindrome(argv[1])) 20 { 21 printf("\nThe entered string \"%s\" is Palindrome.\n", argv[1]); 22 } 23 else 24 { 25 printf("\nThe entered string \"%s\" is not Palindrome.\n", argv[1]); 26 } 27 return 0; 28 } 29 30 int isPalindrome(char str[]) 31 { 32 char *start = str; 33 char *end; 34 int len = strlen(str); 35 if (len == 0) 36 { 37 return 1; 38 } 39 end = str + (len - 1); 40 while (start < end) 41 { 42 if (*start != *end) 43 { 44 return 0; 45 } 46 start++; 47 end--; 48 } 49 return 1; 50 }