写了半个小时,写出来个有问题的程序,明天用gdb调试以下看看问题出在哪里:
#include
void reverse_string(char *string)
{
int i,length;
length = 0;
char tmp;
while (*string++ != '\0')
length += 1;
printf("length:%d\n",length);
string -= length;
string -= 1;
for (i=0; i<=((length-1)/2); i++)
{
tmp = string[i];
string[i] = string[length-1-i];
string[length-1-i] = tmp;
}
}
int main(void)
{
char *str = "hello a string heihei";
reverse_string(str);
//printf("%s\n",str);
}
阅读(770) | 评论(2) | 转发(0) |