從一個文件讀取行的問題。基本上我的代碼是閱讀一個額外的行比應該與所有變量爲'0'i.e。while(!feof(file))read extra line
如果我的文件是:
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);
}
}
這究竟是爲什麼?謝謝你的幫助!
可能是一個新行(ENTER)是在您的輸入文件的末尾 –
@MaziarBouali否我檢查過,見下文。 – Milk