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

aufgabe-4-gpt-pg-02.c

Blame
  • aufgabe-4-gpt-pg-02.c 1.07 KiB
    #include <stdio.h>
    #include <stdint.h>
    
    #define XBM_WIDTH 14
    #define XBM_HEIGHT 14
    
    static unsigned char xbm_bits[] = {
      0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13,
      0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04,
      0xf0, 0x03, 0x00, 0x00
    };
    
    int main(int argc, char **argv)
    {
      // Öffne die Ausgabedatei
      FILE *output_file = fopen("test.pbm", "w");
      if (output_file == NULL) {
        printf("Fehler beim Öffnen der Ausgabedatei\n");
        return 1;
      }
    
      // Schreibe die PBM-Dateikennung, Breite und Höhe in die Ausgabedatei
      fprintf(output_file, "P1\n%d %d\n", XBM_WIDTH, XBM_HEIGHT);
    
      // Iteriere über jedes Byte im XBM-Array
      for (int i = 0; i < XBM_HEIGHT * (XBM_WIDTH + 7) / 8; i++) {  // Iteriere über jedes Bit im aktuellen Byte
        for (int j = 7; j >= 0; j--) {
          // Lies das aktuelle Bit des XBM-Arrays und schreibe es in die Ausgabedatei
          uint8_t xbm_bit = (xbm_bits[i] >> j) & 1;
          fprintf(output_file, "%c", xbm_bit ? '1' : '0');
        }
      }
    
      // Schließe die Ausgabedatei
      fclose(output_file);
    
      return 0;
    }