Program to determine a word or a phrase is a palindrome in C/C++
I am preparing a code for a user described word or a phrase to be accepted and then specify that whether the code is palindrome or not. I some one can give me some basic idea about it then it would be great? Hope to here from you very sooner.
Re: Program to determine a word or a phrase is a palindrome in C/C++
Ideally you can do coding for the word but for the phrase, it is not at all possible. As you might be knowing that phrase will include "spaces". So how will keep track of those spaces?
Re: Program to determine a word or a phrase is a palindrome in C/C++
Actually, my principle is that my program removes spaces of the sentence or when the program faces a space and it will increase to next character. So in that way the spaces would not be a problem in our code, right?
Re: Program to determine a word or a phrase is a palindrome in C/C++
In my opinion the biggest problem is not space but the storage of phrases that you must perform before!
Re: Program to determine a word or a phrase is a palindrome in C/C++
See the below code:
Code:
# include <stdio.h>
# include <string.h>
char sentence [50] = "Johnson and Johnson";
char temp [50];
int i;
int LEN;
for (i = 0; sentence! = "\ 0"; + + i)
+ + LEN;
for (i = 0; i <LEN; + + i)
temp = sentence [- LEN];
if (strcmp (temp, sentence))
printf ( "The sentence is a palindrome");
else
printf ( "The sentence is not a palindrome");
This should work and will give you the out as:
Quote:
The sentence is not a palindrome