Hello I have been working on this program for a few days and have gotten stuck. I allow the user to enter in a string and remove special characters and turn upper case characters to lower case. after all that is done i compare the characters in the string to see if it is a palindrome. My program keeps returning "not a palindrome" any help would be much appreciated thank you.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char removing_char (char *str)
{
	char *p1=str;
	char *p2=str;
	p1 = str;
	
	while(*p1 != 0)
	{
		if(ispunct(*p1) || isspace(*p1)) 
	{
      		++p1;
    }
    else
    *p2++ = *p1++;
}
*p2=0;

return 0;	
}

char change_capt (char *str)
{
	int i;
	
	for(i=0; str[i] != '\0'; i++)
	{
		str[i] = tolower(str[i]);
	}
	
	return 0;
}


int ispalindrome (char *str, int length)
{
	
	
	if(str[0] == str[length-1])
	{
		return ispalindrome(str+1, length-2);
	}
	else
	return 0;
}
	
	

int main(void)
{	
	char str[256];
	int result;
	
	printf("Please enter your string:\n");
	fgets(str, 256, stdin);
	
	change_capt (str);
	removing_char(str);
	
	result = ispalindrome(str, strlen(str));
	
	if(result == 1)
	{
		printf("This is a Palindrome string\n");
	}
	else
	printf("This is not a Palindrome string\n");
	
	

exit(0);
}
int ispalindrome (char *str, int length)
{
	
	if(str[0] == str[length-1])
	{
		if(length>1)
			return ispalindrome(str+1, length-2);
		else
			return 1;
	}
	else
	return 0;
}

Make the following changes to your function.
I hope it will help if not feel free to ask your problem

int ispalindrome (char *str, int length)
{
	
	if(str[0] == str[length-1])
	{
		if(length>1)
			return ispalindrome(str+1, length-2);
		else
			return 1;
	}
	else
	return 0;
}

Make the following changes to your function.
I hope it will help if not feel free to ask your problem

Thank you works perfectly now I really appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.