帮忙分析一下程序的问题,怎么理解?
#include <stdio.h>#include <string.h>
void reverse_str(char * ch);
int main(void)
{
char c[] = "Can you reverse me?"; //当这里把char c[]改成char *s的时候结果就出错,是什么原因啊
printf("original string c: %s\n", c);
reverse_str(c);
printf("reversed string after calling reverse_str: %s\n", c);
return 0;
}
void reverse_str(char *ch)
{
int len;
int i;
char temp;
len = strlen(ch)-1;
for(i = 0; i < len-i; i++)
{
temp = ch[i];
ch[i] = ch[len-i];
ch[len-i] = temp;
}
ch[len+1] = 0;
}