Skip to content
Snippets Groups Projects
Select Git revision
  • d48edcd327479e7a230e1a34684f251a5cd47337
  • master default protected
  • 2018ws
  • 2017ws
  • 2016ws
5 results

string-ops-12.s

Blame
  • Forked from Peter Gerwinski / hp
    Source project has a limited visibility.
    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;
    }