Skip to content
Snippets Groups Projects
Select Git revision
  • 4d8d84da7f037e8b5835a4bc539c34c523231474
  • 2025ss default
  • 2024ss
  • 2023ss
  • 2022ss
  • 2021ss
  • 2020ss
  • 2019ss
  • 2018ss
9 results

README

Blame
  • 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;
    }