我在从文件中读取行时遇到问题。基本上我的代码比它应该多读一行,所有变量都是'0'ie
如果我的文件是:
0, 0, 3, 64, 0, 0, 0, 0
2, 0, 6, 64, 0, 0, 0, 0
4, 0, 4, 64, 0, 0, 0, 0
6, 0, 5, 64, 0, 0, 0, 0
8, 0, 2, 64, 0, 0, 0, 0
它将读取:
Object 1: 0, 0, 3, 64, 0, 0, 0, 0
Object 2: 2, 0, 6, 64, 0, 0, 0, 0
Object 3: 4, 0, 4, 64, 0, 0, 0, 0
Object 4: 6, 0, 5, 64, 0, 0, 0, 0
Object 5: 8, 0, 2, 64, 0, 0, 0, 0
Object 6: 0, 0, 0, 0, 0, 0, 0, 0
这是我的读取算法:
while (!feof(pfile)) {
PcbPtr p = createnullPcb();
fscanf(pfile, "%d,%d,%d,%d,%d,%d,%d,%d", &p->arrivaltime, &p->priority, &p->remainingcputime,
&p->memalloc, &p->pr, &p->sc, &p->mo, &p->cd);
char cwd[1024];
char *tmp = getcwd(cwd, sizeof(cwd));
strcat(tmp, "/process");
p->args[0] = tmp;
p->args[1] = NULL;
if (!headi) {
headi = p;
}
else {
enqPcb(&headi, p);
}
}
为什么会这样?谢谢你的帮助!