小编nei*_*992的帖子

使用指针在我自己的strcat中的总线错误

我正在做strcat函数的指针版本,这是我的代码:

void strcat(char *s, char *t);

int main(void) {
   char *s = "Hello ";
   char *t = "world\n";

   strcat(s, t);

   return 0;
}

void strcat(char *s, char *t) {
  while (*s)
    s++;

  while ((*s++ = *t++))
    ;
}
Run Code Online (Sandbox Code Playgroud)

这看起来很简单,但在我的Mac OS 10.10.3上运行时会出现总线错误.我看不出为什么......

c pointers strcat

1
推荐指数
1
解决办法
268
查看次数

标签 统计

c ×1

pointers ×1

strcat ×1