我正在读取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