Skip to content
Snippets Groups Projects
Commit 95c0a30e authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispielprogramme 28.1.2019

parent 0ba26432
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdint.h>
int main (void)
{
int width = 16;
int height = 16;
FILE *f = fopen ("test.pbm", "w");
fprintf (f, "P4\n%d %d\n", width, height);
uint16_t data = 1;
for (int i = 0; i < 16; i++)
{
uint8_t right_half = data & 0x00ff;
uint8_t left_half = (data & 0xff00) >> 8;
fprintf (f, "%c%c", left_half, right_half);
data <<= 1;
}
return 0;
}
File added
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("test.pbm", "r");
char id[42];
int width, height;
fscanf (f, "%s", id); // should be "P4"
printf ("%s\n", id);
fscanf (f, "%d", &width);
fscanf (f, "%d", &height);
printf ("%d %d\n", width, height);
return 0;
}
#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);
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 = 0; i < 7; i++)
if (data & (1 << i))
printf ("*");
else
printf (" ");
}
printf ("\n");
}
return 0;
}
#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 = 0; i < 7; i++)
if (data & (1 << i))
printf ("*");
else
printf (" ");
}
printf ("\n");
}
return 0;
}
#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;
}
#include <stdio.h>
#include <stdint.h>
int main (void)
{
FILE *f = fopen ("molpy-right.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;
}
File added
20190128/test.png

247 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment