1 //递归反向打印字符串
2 void reversePrint(const char *str)
3 {
4 if(str == NULL)
5 return;
6 if(*str == '\0')
7 return;
8 reversePrint(str+1);//递归下一个字符
9 printf("%c",*str); //打印当前字符
10 }
下面是非递归打印
//非递归反向打印字符串
void nonReversePrint(const char *str)
{
if(str == NULL)
return;
//获取字符串的长度
int index = strlen(str) - 1;
while(index >= 0)
{
printf("%c",str[index]);
index--;
}
}