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);
}

Recommended Answers

All 3 Replies

Welcome to Daniweb.

This section is for general introduction of new members only.

Kindly post your question in the proper section of the forum.

Welcome to Daniweb.:)

I have asked the mods to move this post to our web development forums.

Already double posted in C section. Please follow discussion over there, as this thread is now closed.

@Prisms please read forum rules and do not double post as this is not welcome

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.