我试图从文件中读取一些数据并将其插入队列,Insert函数运行良好,并且我尝试使用printfs捕获错误。我在while()行中看到错误。像这样的文件形式的数据
12345 2
11232 4
22311 4
22231 2
void read_file(struct Queue *head){
FILE *fp;
int natid;
int cond;
fp=fopen("patients.txt","r");
while (fscanf(fp,"%d %d", natid, cond) != EOF)
insert(head,natid,cond);
fclose(fp);}
您必须将指针传递到fscanf()
存储值的位置,并检查所有预期的转换是否成功:
while (fscanf(fp, "%d %d", &natid, &cond) == 2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句