OUTPUT (after running):
Enter your string: DR. RAJIV
Enter your second string: CHOPRA
Concatenated string is: DR. RAJIV CHOPRA
V. The strrev( ) Function
The strrev( ) function reverses the string.
Syntax
strrev(str);
Here the contents of string str are reversed and stored in str.
Before continuing the discussion, please write the following programs.
Example
1: Write a C program to find whether a given string is a palindrome.
Solution 1: Any number or word or string that reads the same from left-to-right as it does
from right-to-left is a palindrome (e.g., 121, TOOT, MADAM, etc.).
The program is as follows:
#include
#include
main( )
{
char name1[80], name2[80];
printf(“\nEnter your string:”);
gets (name1);
strcpy(name2, name1);
strrev(name1);
if (strcmp(name1, name2) = = 0)
printf(“Given string is a palindrome”);
else
printf(“Given string is not a palindrome”);
}
Do'stlaringiz bilan baham: |