C Language Examples - String Reversal
Use recursion to reverse a string.
Example - String Reversal
#include <stdio.h>
void reverseSentence();
int main()
{
printf("Enter a string:");
reverseSentence();
return 0;
}
void reverseSentence()
{
char c;
scanf("%c", &c);
if( c != '\n')
{
reverseSentence();
printf("%c",c);
}
}
The output result is:
输入一个字符串: example boonurother extensions