I am accepting a string as a command line argument. I want to check whether the inputted string is a palindrome or not and print the result. I have written the following code. But its displaying the result 'not palindrome' for all inputs.
#include<stdio.h>
#include<string.h>
int main(int argc, char argv[20]) {
int i;
int l = strlen(argv);
char str[20];
bzero(str, 20);
for(i=0; i<l; i++)
{
str[i] = argv[i+2];
}
int flag;
int len = strlen(str);
for(i=0; i< len/2; i++)
{
if(str[i] == str[len - (i+2)])
{
flag = 0;
}
else
{
flag = 1;
break;
}
}
if(flag == 0)
printf("Palindrome\n");
else
printf("Not a palindrome\n");
}