Ok, I know how the palindrome program works. I did it earlier this year, and now the teacher wants it using command line arguments.
PHP Code:
int main(int argc, char *argv[])
{
int len, i, run,
match = 1;
if (argc > 1)
{
len = strlen(argv[1]);
run = len/2;
for( i=0; i<run; i++ )
{
if ( argv[1][i] != argv[i][len-i-1] )
{
printf("%d: %c != %c\n", i, argv[1][i], argv[1][len-i-1]);
match = 0;
}
else
printf("%d: %c == %c\n", i, argv[1][i], argv[1][len-i-1]);
}
if (match)
printf("%s is a palindrome!!!\n\n", argv[1]);
else
printf("%s is not a palindrome.\n\n", argv[1]);
}
}
I have been working on a project for a few days, and my brain is fried. Can anyone tell me what I have messed up here. If if give call it like "prog abba", it says the a's are not equal, but the b's are. Any ideas?
Thanks for any help.