此代码编译时没有错误,但打开应用程序后,它会显示:
file.exe has stopped working
#include <string.h>
#include <stdio.h>
int main() {
char *a = 'Hello';
char *b = 'World';
strcat(a,b);
puts(a);
}
我哪里出错了?
最佳答案
您需要分配足够的空间并使用双引号而不是单引号。您可以使用数组。
#include <string.h>
#include <stdio.h>
int main() {
char a[20] = "Hello";
char b[10] = "World";
strcat(a,b);
puts(a);
}
关于c - 声明 char* 不适用于 strcat(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50967927/