Reverse characters of a string.
#include <string.h> | Required only for function declarations |
char *_strrev( char *string );
char __far * __far _fstrrev( char __far *string );
string | String to be reversed |
The _strrev function reverses the order of the characters in string. The terminating null character ('\0') remains in place.
The _fstrrev function is a model-independent (large-model) form of the _strrev function. The behavior and return value of _fstrrev are identical to those of the model-dependent function _strrev, with the exception that the argument and return value are far pointers.
These functions return a pointer to the altered string. There is no error return.
_strrev
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_fstrrev
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* STRREV.C: This program checks an input string to see whether it is a
* palindrome: that is, whether it reads the same forward and backward.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[100];
int result;
printf( "Input a string and I will tell you if it is a palindrome:\n" );
gets( string );
/* Reverse string and compare (ignore case): */
result = _strcmpi( 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 );
}
Input a string and I will tell you if it is a palindrome:
Able was I ere I saw Elba
The string "Able was I ere I saw Elba" is a palindrome