#include <stdio.h>
#include <stdlib.h>
void load_image_data(char* f_name)
{
FILE* fp;
char buf[640];
errno_t err;
int x_size, y_size;
int max_gray;
int ix, iy;
err = fopen_s(&fp, f_name, "rb");
if (err) {
return;
}
// P5
fgets(buf
, sizeof buf
, fp
); if (buf[0] != 'P' || buf[1] != '5') {
return;
}
// x y
x_size = y_size = 0;
while (x_size == 0) {
fgets(buf
, sizeof buf
, fp
); if (buf[0] == '#') continue;
sscanf_s(buf, "%d%d", &x_size, &y_size);
}
// max
max_gray = 0;
while (max_gray == 0) {
fgets(buf
, sizeof buf
, fp
); if (buf[0] == '#') continue;
sscanf_s(buf, "%d", &max_gray);
}
printf("%d %d\n", x_size
, y_size
);
for (iy = 0; iy < y_size; iy++) {
for (ix = 0; ix < x_size; ix++) {
}
}
}
int main()
{
char f_name[256];
int i;
for (i = 0; i < 10; i++) {
sprintf_s(f_name, _countof(f_name), "std%d.pgm", i);
load_image_data(f_name);
}
for (i = 0; i < 10; i++) {
sprintf_s(f_name, _countof(f_name), "n%d.pgm", i);
load_image_data(f_name);
}
load_image_data("number2.pgm");
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnZvaWQgbG9hZF9pbWFnZV9kYXRhKGNoYXIqIGZfbmFtZSkKewoJRklMRSoJZnA7CgljaGFyCWJ1Zls2NDBdOwoJZXJybm9fdAllcnI7CglpbnQJeF9zaXplLCB5X3NpemU7CglpbnQJbWF4X2dyYXk7CglpbnQJaXgsIGl5OwoKCWVyciA9IGZvcGVuX3MoJmZwLCBmX25hbWUsICJyYiIpOwoJaWYgKGVycikgewoJCWZwcmludGYoc3RkZXJyLCAiZm9wZW5fc1xuIik7CgkJcmV0dXJuOwoJfQoKCS8vIFA1CglmZ2V0cyhidWYsIHNpemVvZiBidWYsIGZwKTsKCWlmIChidWZbMF0gIT0gJ1AnIHx8IGJ1ZlsxXSAhPSAnNScpIHsKCQlmcHJpbnRmKHN0ZGVyciwg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