我正在做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上运行时会出现总线错误.我看不出为什么......