Credits

Saturday, February 21, 2009

String Manipulation with C

C makes use of string functions to perform certain string operation.

Below is a program that checks whether the word encoded is a palindrome or not.
Sample palindromes are the following:

mom
dad
noon
wow
etc.

Palindromes are words that can be read forward or backward. Check the program below to test if your words encoded are palindrome or not.



[+/-] show/hide



#include stdio.h /*enclose the library with <> */
#include string.h /*enclose the library with <> */

main()
{
char w1[10],w2[10],wr[10];
int same;
clrscr();
printf("enter a word\n");gets(w1);
strcpy(w2,w1); /* copies the value of string w1 to w2 */
strcpy(wr,strrev(w2)); /* reverses the value of string w2*/
same=strcmpi(w1,wr); /* compares the two strings */
if (same==0)
printf("Your word %s is a palindrome.",w1);
else
printf("Your word %s is not a palindrome",w1);
getch();
}

AddThis