>what does the "i" stand for??
It is an index into the array.
Rather than "removing all spaces" -- because you might also want to remove punctuation or control characters -- aren't you really trying to keep only letters?
Code:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char sentence[40] = "Damn, I Agassi.\tMiss again mad.";
int i, j = 0;
printf("sentence = \"%s\"\n", sentence);
for ( i = 0; sentence[i] != '\0'; ++i )
{
if ( isalpha(sentence[i]) )
{
sentence[j++] = tolower(sentence[i]);
}
}
sentence[j] = '\0';
printf("sentence = \"%s\"\n", sentence);
for ( i = 0, --j; i < j; ++i, --j )
{
if ( sentence[i] != sentence[j] )
{
puts("Not a palindrome");
return 0;
}
}
puts("Looks like a palindrome to me");
return 0;
}
/* my output
sentence = "Damn, I Agassi. Miss again mad."
sentence = "damniagassimissagainmad"
Looks like a palindrome to me
*/