[問題] feof無窮的問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
ubuntu
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
在add的函式會變成無窮回圈,不斷的scanf,似乎找不到eof?
程式碼(Code):(請善用置底文網頁, 記得排版)
main()
{
if ((cptr=fopen("tmp.dat","r+"))==NULL)
printf("Can't open file\n");
initial(cptr);
add(cptr);
return;
}
void initial(FILE *ptr)
{
int i;
Test test = {"abc","abc","0"};
rewind(ptr);
for(i=0;i<SIZE;i++){
fwrite(&test,sizeof(Test),1,ptr);
}
}
void add(FILE *ptr)
{
Test test;
rewind(ptr);
while(!feof(ptr)){
printf("Input\n");
scanf("%s%s%s",test.test1,test.test2,test.test3);
fwrite(&test,sizeof(Test),1,ptr);
}
}
補充說明(Supplement):
小弟不才,請各位幫忙,謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 36.231.81.243
推
03/20 16:32, , 1F
03/20 16:32, 1F
→
03/20 16:33, , 2F
03/20 16:33, 2F
→
03/20 17:34, , 3F
03/20 17:34, 3F
→
03/20 17:36, , 4F
03/20 17:36, 4F
→
03/20 18:55, , 5F
03/20 18:55, 5F
→
03/20 19:47, , 6F
03/20 19:47, 6F
→
03/20 19:53, , 7F
03/20 19:53, 7F
推
03/20 20:08, , 8F
03/20 20:08, 8F
→
03/21 00:08, , 9F
03/21 00:08, 9F
→
03/21 00:10, , 10F
03/21 00:10, 10F
→
03/21 00:13, , 11F
03/21 00:13, 11F
→
03/21 01:12, , 12F
03/21 01:12, 12F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章