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