<分区>
Possible Duplicate:
Why do I get a segmentation fault when writing to a string?
假设我有 s = "Hello"。我希望它转换成 s = "Hello"。
这是我的
# include <stdio.h>
# include <string.h>
main()
{
char *s = " Hello";
char *shift(char *, int);
shift(s+1,-1);
printf("%s", s);
}
char *shift (char *str, int units)
{
if (units < 0)
{
for (; *str != '\0'; str++)
*(str + units) = *str;
*(str + units) = '\0';
return str-strlen(str)-units;
}
}
程序正在终止!甚至没有显示错误。我哪里错了..
最重要的是,是什么让这个程序将控制权交给操作系统来终止?