这已经困扰了我一段时间。
struct person {
char name[15];
int age;
};
struct person me;
me.name = "nikol";
当我编译时出现此错误:
错误:从类型'char *'分配给类型'char [15]'时类型不兼容
我在这里错过明显的东西吗?
数组是C语言中的二等公民,它们不支持分配。
char x[] = "This is initialization, not assignment, thus ok.";
这不起作用:
x = "Compilation-error here, tried to assign to an array.";
使用库函数或手动为其自身复制每个元素:
#include <string.h>
strcpy(x, "The library-solution to string-assignment.");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句