Syntax
#include <string.h> char *strrev(char *string);Description
strrev reverses the order of the characters in the given string. The ending null character (\0) remains in place.
strrev returns a pointer to the altered string. There is no error return value.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int palindrome(char *string)
{
char *string2;
int rc;
/* Duplicate string for comparison */
if (NULL == (string2 = strdup(string))) {
printf("Storage could not be reserved for string\n");
exit(EXIT_FAILURE);
}
/* If result equals 0, the string is a palindrome */
rc = strcmp(string), strrev(string2));
free(string2);
return rc;
}
int main(void)
{
char string[81];
printf("Please enter a string.\n");
scanf("%80s", string);
if (palindrome(string))
printf("The string is not a palindrome.\n");
else
printf("The string is a palindrome.\n");
return 0;
/****************************************************************************
Sample output from program:
Please enter a string.
level
The string is a palindrome.
... or ...
Please enter a string.
levels
The string is not a palindrome.
****************************************************************************/
}
Related Information