简体   繁体   English

从类型int分配类型char [2]时编译“不兼容类型”的错误

[英]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.

相关问题 从int类型分配给char []类型时,类型不兼容 - Incompatible types when assigning to type char[] from type int 从“ int”类型分配给“ char * [12]”类型时不兼容的类型 - incompatible types when assigning to type 'char *[12]' from type 'int' 错误:从类型&#39;digestInfo&#39;分配给类型&#39;char *&#39;时类型不兼容 - error: incompatible types when assigning to type ‘char *’ from type ‘digestInfo’ 从“ char *”类型分配给“ char [50]”类型时不兼容的类型 - incompatible types when assigning to type 'char[50]' from type 'char *' 从&#39;char *&#39;类型分配给char [32]类型时,类型不兼容 - Incompatible types when assigning to type char[32] from type 'char*' 从“ char *”类型分配给“ char [5]”类型时不兼容的类型 - incompatible types when assigning to type 'char[5]' from type 'char *' 错误:从类型&#39;char *&#39;分配给类型&#39;char [25]&#39;时类型不兼容 - Error: incompatible types when assigning to type ‘char[25]’ from type ‘char *’ 从二维数组中的“char *”类型错误分配给“char [100] [100]”类型时不兼容的类型 - Incompatible types when assigning to type 'char[100][100]' from type 'char *' error in 2d array 从Int类型分配给&#39;struct PartyInfo&#39;类型时不兼容的类型 - Incompatible types when assigning to type 'struct PartyInfo' from type Int 从“ int”类型分配给“ memstruct”类型时不兼容的类型 - incompatible types when assigning to type ‘memstruct’ from type ‘int’
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM