我想使用两个字符指针打印出"Hello - World",但是我遇到了"Segmentation fault (core dumped)"的问题。
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define Hyphen " - "
int main()
{
char* x="Hello";
char* y="'World'";
strcat(x, Hyphen);
strcat(x, y);
printf("%s",x);
return 0;
}
char x[20]
代替char* x
。 - Blaze