神器时代大全:设计一个递归函数将给定的串逆序输出

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/25 15:43:49
C++程序,不是C
答复2中有一处错误,看看能不能改过来

参数说明:
1. s 原始字符串
2. n 原始字符串长度
处理说明:
该函数执行完毕,原始字符串已经是逆序了

void invert(char s[], int n)
{
char temp;
if(n>1)
{
invert(s+1, n-2);
temp = s[0];
s[0] = s[n-1];
s[n-1] = temp;
}
}

试一下这个程序:
void printstr(char *p)
{
if(*p!='\0')
printstr(++p);
if(*p!='\0')
printf("%c",*p);
}
main()
{
char *p;
p="abcdefg";
printstr(p);
}