我目前正在编写一个处理 PPM 文件的程序(P6 类型,而不是 P3)问题是某些图像具有字节 0x1b,根据 ascii 表,它被称为“ESC”
以下几乎是我的代码:
// 那里的所有包含,, , ...
int main(void)
{
FILE *finput;
int number[7];
char r, g, b;
finput = fopen("my.ppm", "r");
/*
The code where I read the P6 numRows numColumns 255\n
...Lets assume that part works well
*/
while(!feof(finput))
{
num[0] = fscanf(finput, "%c", &r); // the "num[] = " part is for debugging
num[1] = fscanf(finput, "%c", &g);
num[2] = fscanf(finput, "%c", &b);
printf("%d\n", num[0]);
printf("%d\n", num[1]);
printf("%d\n", num[2]);
}
return 0; //or whatever...
}
出于某种原因,fscanf 在读取“ESC”字节后开始返回-1(但读取它的字节不返回-1)
所以样本输出将是:
1 -1 -1
另一方面,我阅读了“while(!feof()) 总是错误的”和关于使用 fscanf 的大文件的内容,但我的 ppm 图像不大于 500x500 像素...
为了能够继续阅读,我可以/应该做什么?
谢谢您的帮助!