可能重复:
为什么在写入字符串时会出现分段错误?
假设我有 s =“你好”。我希望它转换成 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;
}
}
程序终止!甚至没有显示错误。我哪里错了..
最重要的是,是什么让这个程序将控制权交给操作系统来终止?