Select Git revision
show-pbm-4.c 632 B
#include <stdio.h>
#include <stdint.h>
int main (void)
{
FILE *f = fopen ("test.pbm", "r");
char id[42];
int width, height;
fscanf (f, "%s", id); // should be "P4"
fscanf (f, "%d", &width);
fscanf (f, "%d", &height);
uint8_t dummy;
fscanf (f, "%c", &dummy);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < (width + 7) / 8; x++)
{
uint8_t data;
fscanf (f, "%c", &data);
for (int i = 7; i >= 0; i--)
if (data & (1 << i))
printf ("*");
else
printf (" ");
}
printf ("\n");
}
return 0;
}