so I am making a palindrome checker that ignores any white space or special characters. Below is part of my function. What it does is it takes a c string as an argument, then I create another c string in order to remove the whitespaces and special character from the orignal. When I output the second c string, it still will have the whitespaces or special characters. Could some explain why it is doing that? Thanks
bool isPalindrome(char *line)
{
//variables
bool palindrome = true;
int length = strlen(line);
int count = 0;
//copy line to line2 with no spaces and no punctuation
char *line2 = new char[length + 1];
int count2 = 0;
for(int i = 0; i < length; i++)
{
if(line[i] != ' ' && ispunct(line[i]) == false)
{
line2[count2] = line[i];
count2 ++;
}
}
for(int i = 0; i < count2; i++)
cout << line[i];
line2[length] = '\0';