[英]compile error of "incompatible types when assigning to type char[2] from type int
I am having the above mentioned compile error. 我有上面提到的编译错误。 The line of code is this:
代码行是这样的:
if ((strcmp(tempDept, data[1].Dept)==0) && tempCourse == data[i].course){
if (tempDay = data[i].meet_days &&
tempTime == data[i].start.hour){ //<---This line
printf("this worked");
}
}
Here is my structs declarations: 这是我的结构声明:
typedef enum {MW, TR} days;
typedef struct {
int hour, min;
} Time;
typedef struct {
char Dept[5];
int course, sect;
days meet_days;
Time start, end;
char instr[20];
} sched_record;
And here is my list off variables: 这是我的变量列表:
int switchInput;
int i = 0;
int tempCourse = 0;
char tempDept[5];
char tempDay[2];
int tempTime;
//char tempTime[1];
FILE *filePointer;
sched_record data[MAX_RECORD];
Can someone tell me how to fix this? 谁能告诉我如何解决这个问题?
if (tempDay = data[i].meet_days
你错过了双等号==
tempDay = data[i].meet_days
This couses a problem because tempDay
is char array of length 2 and meet_days
is enum days
. 这会产生问题,因为
tempDay
是长度为2的char数组, meet_days
是enum days
。 And in C constants in enums are just of int
type. 在枚举中的C常量只是
int
类型。 Another problem that you can't assign int
to char array
itself. 另一个问题是你不能将
int
赋给char array
本身。 Maybe you wanted an equal sign ==
? 也许你想要一个等号
==
? Now you must think how to convert int
enum value to char[2]
. 现在你必须考虑如何将
int
枚举值转换为char[2]
。 One way is use sprintf()
to accomplish that. 一种方法是使用
sprintf()
来实现这一点。 But concrete implementation depends on your interpretation of enum constants. 但具体的实现取决于你对枚举常量的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.