我正在讀取stdin
中的值,我想繼續讀取文件直到我完全讀完它,所以我使用關於while(!EOF)的問題
while(!EOF){ scanf(...) }
然而,代碼片段似乎沒有做任何事情,
while(!EOF){
scanf("%d %d %d %d", &imageWidth, &imageHeight, &safeRegionStart, &safeRegionWidth);
printf("---imageWidth=%d imageHeight=%d safeRegionStart=%d safeRegionWidth=%d---\n", imageWidth, imageHeight, safeRegionStart, safeRegionWidth);
totalP = imageWidth * imageHeight ;
totalSafeP = imageHeight * safeRegionWidth;
printf("---total # of pixels: %d Total # of safe Pixels: %d---\n\n", totalP, totalSafeP);
i=1;
while(i!=totalP)
{
i++;
scanf("%d", &pixel);
printf("\nValue of pixel %d", pixel);
}//End for scanning all pixels*/
}//while loop
編輯:我修復了
while(scanf("%d %d %d %d", &imageWidth, &imageHeight, &safeRegionStart, &safeRegionWidth)==4&&!feof(stdin)) { }
!feof(stdin)
可能沒有必要。
那麼它有什麼作用?你調試了嗎? – Kangkan 2011-06-08 07:38:31
它沒有做任何事情,因爲while(!EOF)被評估爲false,所以while永遠不會被執行。 – 2011-06-08 08:09:15