#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char string[20];
void convert(int n , int N)//n为元素的下标,N为数组的实际长度
{
if(0 == N)
{
printf("your input is empty!\n");
return;
}
if(n < N) {
convert(n+1 , N);
printf("%c" ,string[n]);
}
}
int main()
{
printf("please input a string :\n");
scanf("%s",string);
printf("please output the string after convert:\n");
convert( 0 , strlen(string) );
printf("\n");
return 0;
}
这是一个简单的,将字符串反转输出的例子,测试用例:输入helloworld,输出dlrowlleh。输入2345&* 输出*&5432。
此程序对于一般的纯字符串输入,输出能达到预期,但其鲁棒性还不够,如输入为空或者输入为一些其它字符时,输出不一定为原字符(需要考虑其转化为字符的可能性)或者未达到预期输出