Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有结构:
struct person { char firstname[]; };
和方法:
void abcde (person* a, char firstchar[]) { a->firstname = firstchar; }
gcc 抛出这个:
char*' tochar[0u]'赋值中的类型不兼容
char*' to
如何解决这个问题呢?感谢帮助!
您不能分配给数组。您想要一个指针,或者将一个指针的内容复制到另一个指针。
struct person { char* firstname; }; void abcde (person* a, char firstchar[]) { a->firstname = firstchar; }
firstchar在函数参数中是一个指针,而不是一个数组!the[]仅仅是一种语法上的便利。不是这种情况char firstname[];,它是一个数组。
firstchar
[]
char firstname[];