plz tell me how can i cheack a strin is palindrome or not

Comments
Very bad since you already proved that you have enough brain to come to this forum...
Are you a complete idiot? Not only did you resurrect a thread, the thread has nothing to do with your question.

plz tell me how can i cheack a strin is palindrome or not

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{char a[20],b[20];
cout<<"enter the string"<<endl;
gets(a);
strcpy(b,a);
strrev(b);
if(strcmpi(a,b)==0)
cout<<"palindrome"<<endl;
else
cout<<"nay"<<endl;
getch();
}

Comments
Do NOT do people's homework for them, especially without CODE Tags and using bad code.

Answering a C question with C++ is worthless. And using gets() and getch() is so wrong it's close to criminal.

And do I really need to mention CODE Tags? The Member Rules are quite clear...

Answering a C question with C++ is worthless. And using gets() and getch() is so wrong it's close to criminal.

And do I really need to mention CODE Tags? The Member Rules are quite clear...

What I find to be even more disturbing is the fact that this guy's created an account for improperly answering this question.

It's funny because I just had to do this for my programming class. You are going to have to do a series of things.

Because strings are dealt with in arrays you are going to need to remove all of the spaces and punctuation marks. (My suggestion is rather than excluding the unwanted characters, to only accept the types of characters you want. aka: lowercase and uppercase characters.)

After removing the unwanted characters you need to covert all of the characters that are uppercase to lowercase.

Once you have removed all of the unwanted characters and made it all lowercase, then you can reverse the array and see if it is equivalent to the un-reversed.

Obviously you are going to need multiple variables to hold all of the info. I would also suggest breaking each of these steps into individual functions so you can use pointers.

Good luck! Have fun!

Hello!

I had something easier on my mind.. such as a function that takes as a parameter an array of characters and returns 1 if the content of the array is palindrome and 0 if the content of the array isn't palindrome..In order to check if the character sequence is palindrome i just have to compare the integer ASCII code of the first character with last, the second character with next to last etc... Am i right..?? As a hint i'll write this idea in a function:

int palindrome(char *s)
  {  
	int i, len, check;
	len = strlen(s);
	check = 1;                
	i = 0;

	do
	{
	if(s[i] != s[len-i-1])
	  check = 0;
		i++;
	} while(i < len);
    
    return check;
  }

Edited 6 Years Ago by vanalex: n/a

That doesn't cover all cases though. Ex: "Ma is as selfless as I am."

There are punctuation, capitalization, and spacing issues to be dealt with. That's why I suggest going through the process of breaking it out into separate functions.

This article has been dead for over six months. Start a new discussion instead.