STRREV(DOS) UNIX System V STRREV(DOS)
Name
strrev - Reverses the order of characters in a string.
Syntax
#include <string.h>
char *strrev(string)
char *string;
Description
The strrev function reverses the order of the characters in
string. The terminating null character (\0) remains in
place.
Return Value
The strrev function returns a pointer to the altered string.
There is no error return.
See Also
strcpy(DOS), strset(DOS)
Example
#include <string.h>
#include <stdio.h>
char string[100];
int result;
main()
{
printf("Input a string and I will tell");
printf("you if it is a palindrome: ");
gets(string);
/* Reverse string and compare: */
result = strcmp(string,strrev(strdup(string)));
if (result == 0)
printf("The string \"%s\" is a palindrome\n\n",
string);
else
printf("The string \"s\" is not a palindrome\n\n",
string);
}
This program checks an input string to see whether it is a
palindrome: that is, whether it reads the same forward and
backward. The program checks this by comparing a string
named string with a copy of string that has been reversed
using strrev.
(printed 7/6/89)