输入一串以“!”结束的字符串,按逆序输出,要求用递归,请问这样写有什么问题吗,结果运行出一堆乱码。
#include<stdio.h>
#include<malloc.h>
int main()
{
void convert(char* s);
int i;
char s[100], ch;
ch = getchar();
for (i = 0; ch != '!'; i++)
{
s[i] = ch;
ch = getchar();
}
convert(s);
return 0;
}
void convert(char* s)
{
if (*s == '!')
return;
else
{
convert(s+1);
printf("%c", *s);
}
}