【发布时间】:2020-05-07 21:18:01
【问题描述】:
对于empF[i],我遇到了这个错误“下标值不是数组、指针或向量”
这是我的代码
employee empF[100];
int i=0;
void test(){
FILE *fp;
employee empF;
fp=fopen("employee.csv","r");
employee temp;
char x[100];
while(fgets(x,100,fp)!=NULL){
removeCommas(x);
sscanf(x,"%d %s %ld %s %d",&(temp.employee_id),temp.employee_name,&(temp.phno),temp.shift,&(temp.area_code));
empF[i].employee_id=temp.employee_id;
empF[i].employee_name=temp.employee_name;
empF[i].phno=temp.phno;
empF[i].shift=temp.shift;
empF[i].area_code=temp.area_code;
i+=1;
}
fclose(fp);
}
这是员工结构
typedef struct employee
{
int employee_id;
char employee_name[20];
long int phno;
char shift[10];
int area_code;
}employee;
如果我不使用结构数组,它似乎运行得很好。我到底错过了什么?
【问题讨论】:
标签: c file csv runtime-error structure