C结构编译错误 [英] C Struct Compile Error
本文介绍了C结构编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么以下code产生编译时错误?我似乎无法明白为什么类型不匹配。
的typedef的char f_string [MAX_CHARS + 1]; / *字符串为每个字段* // *
*一个解析CSV线,字段的数量和高达MAX_FIELDS自己。
* /typedef结构{
INT N字段; / * 0 =>文件结尾* /
f_string场[MAX_FIELDS] / *字段的字符串数组* /
} csv_line;....csv_line SUT;
sut.field [0] =名称; //编译时错误。
误差为:
错误:不兼容的类型赋值
解决方案
sut.field [0]
是的char [MAX_CHARS + 1]
名称,
是为const char *
试试这个:
的strcpy(sut.field [0],姓名);
Why does the following code produce a compile-time error? I cannot seem to see why the types are mismatched.
typedef char f_string[MAX_CHARS+1] ; /* string for each field */
/*
* A parsed CSV line, with the number of fields and upto MAX_FIELDS themselves.
*/
typedef struct {
int nfields ; /* 0 => end of file */
f_string field[MAX_FIELDS] ; /* array of strings for fields */
} csv_line;
....
csv_line sut;
sut.field[0] = "Name, "; //Compile-time error.
Error being:
error: incompatible types in assignment
解决方案
sut.field[0]
is a char[MAX_CHARS+1]
"Name, "
is a const char*
Try this:
strcpy(sut.field[0], "Name, ");
这篇关于C结构编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文