0

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);
}
4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by peter_budo
0

Welcome to Daniweb.

This section is for general introduction of new members only.

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.