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

Vorlesung 26.11.2015

parent fdafe5af
No related branches found
No related tags found
No related merge requests found
Showing
with 785 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
#define FIFO_SIZE 42
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void fatal_error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
void push (int x)
{
if (fifo_pointer < 0 || fifo_pointer >= FIFO_SIZE)
fatal_error ("fifo overflow");
else
fifo[fifo_pointer++] = x;
}
int pop (void)
{
if (fifo_pointer < 1 || fifo_pointer > FIFO_SIZE)
{
fatal_error ("fifo underflow");
return 0;
}
else
return fifo[--fifo_pointer];
}
void dump (void)
{
if (fifo_pointer < 0)
fatal_error ("fifo underflow");
else if (fifo_pointer >= FIFO_SIZE)
fatal_error ("fifo overflow");
else if (fifo_pointer == 0)
printf ("fifo is empty\n");
else
{
printf ("fifo:");
for (int i = 0; i < fifo_pointer; i++)
printf (" %d", fifo[i]);
printf ("\n");
}
}
int main (void)
{
dump ();
push (7);
dump ();
push (13);
dump ();
push (42);
dump ();
printf ("%d\n", pop ()); /* 42 */
dump ();
printf ("%d\n", pop ()); /* 13 */
dump ();
printf ("%d\n", pop ()); /* 7 */
dump ();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define FIFO_SIZE 42
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void fatal_error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
void push (int x)
{
if (fifo_pointer < 0 || fifo_pointer >= FIFO_SIZE)
fatal_error ("fifo overflow");
else
fifo[fifo_pointer++] = x;
}
int pop (void)
{
if (fifo_pointer < 1 || fifo_pointer > FIFO_SIZE)
{
fatal_error ("fifo underflow");
return 0;
}
else
{
int value = fifo[0];
for (int i = 1; i < fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
return value;
}
}
void dump (void)
{
if (fifo_pointer < 0)
fatal_error ("fifo underflow");
else if (fifo_pointer >= FIFO_SIZE)
fatal_error ("fifo overflow");
else if (fifo_pointer == 0)
printf ("fifo is empty\n");
else
{
printf ("fifo:");
for (int i = 0; i < fifo_pointer; i++)
printf (" %d", fifo[i]);
printf ("\n");
}
}
int main (void)
{
dump ();
push (7);
dump ();
push (13);
dump ();
push (42);
dump ();
printf ("%d\n", pop ()); /* 42 */
dump ();
printf ("%d\n", pop ()); /* 13 */
dump ();
printf ("%d\n", pop ()); /* 7 */
dump ();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define FIFO_SIZE 42
int fifo[FIFO_SIZE];
int fifo_read_pointer = 0;
int fifo_write_pointer = 0;
void fatal_error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
void push (int x)
{
if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE)
fatal_error ("fifo overflow");
else
fifo[fifo_write_pointer++] = x;
}
int pop (void)
{
if (fifo_read_pointer < 0 || fifo_read_pointer >= fifo_write_pointer)
{
fatal_error ("fifo underflow");
return 0;
}
else
return fifo[fifo_read_pointer++];
}
void dump (void)
{
/*
if (fifo_pointer < 0)
fatal_error ("fifo underflow");
else if (fifo_pointer >= FIFO_SIZE)
fatal_error ("fifo overflow");
else if (fifo_pointer == 0)
printf ("fifo is empty\n");
else
{
printf ("fifo:");
for (int i = 0; i < fifo_pointer; i++)
printf (" %d", fifo[i]);
printf ("\n");
}
*/
}
int main (void)
{
dump ();
push (7);
dump ();
push (13);
dump ();
push (42);
dump ();
printf ("%d\n", pop ()); /* 42 */
dump ();
printf ("%d\n", pop ()); /* 13 */
dump ();
printf ("%d\n", pop ()); /* 7 */
dump ();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define FIFO_SIZE 42
int fifo[FIFO_SIZE];
int fifo_read_pointer = 0;
int fifo_write_pointer = 0;
void fatal_error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
void push (int x)
{
if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE)
fatal_error ("push: fifo inconsistence");
else
{
fifo[fifo_write_pointer++] = x;
if (fifo_write_pointer >= FIFO_SIZE)
fifo_write_pointer = 0;
if (fifo_write_pointer == fifo_read_pointer)
fatal_error ("fifo overflow");
}
}
int pop (void)
{
if (fifo_read_pointer < 0 || fifo_read_pointer >= FIFO_SIZE)
{
fatal_error ("pop: fifo inconsistence");
return 0;
}
else if (fifo_read_pointer == fifo_write_pointer)
{
fatal_error ("fifo underflow");
return 0;
}
else
{
int value = fifo[fifo_read_pointer++];
if (fifo_read_pointer >= FIFO_SIZE)
fifo_read_pointer = 0;
return value;
}
}
int main (void)
{
int value = 42;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 10; j++)
push (value++);
for (int j = 0; j < 10; j++)
printf ("%d\n", pop ());
}
return 0;
}
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "stack.h"
char screen[WIDTH][HEIGHT];
//Setze alle Einträge in display auf c
void clear (char c)
{
for (int i=0;i<WIDTH;i++)
{
for (int j=0;j<HEIGHT;j++)
{
screen[i][j]=c;
}
}
}
//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
screen[x][y]=c;
}
//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
char c=screen[x][y];
return c;
}
//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
if (getPoint(x,y)==o)
{
putPoint(x,y,c);
push(x+1,y);
push(x-1,y);
push(x,y+1);
push(x,y-1);
}
}
//Gib display aus
void display (void)
{
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
printf("%c",screen[j][i]);
}
printf("\n");
}
}
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "stack.h"
char screen[WIDTH][HEIGHT];
//Setze alle Einträge in display auf c
void clear (char c)
{
for (int i=0;i<WIDTH;i++)
{
for (int j=0;j<HEIGHT;j++)
{
screen[i][j]=c;
}
}
}
//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
screen[x][y]=c;
}
//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
char c=screen[x][y];
return c;
}
//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
push (x, y);
while (!stack_empty ())
{
pop (&x, &y);
if (getPoint (x, y) == o)
{
putPoint (x, y, c);
push (x + 1, y);
push (x - 1, y);
push (x, y + 1);
push (x, y - 1);
}
}
}
//Gib display aus
void display (void)
{
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
printf("%c",screen[j][i]);
}
printf("\n");
}
}
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
char screen[WIDTH][HEIGHT];
//Setze alle Einträge in display auf c
void clear (char c)
{
for (int i=0;i<WIDTH;i++)
{
for (int j=0;j<HEIGHT;j++)
{
screen[i][j]=c;
}
}
}
//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
screen[x][y]=c;
}
//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
char c=screen[x][y];
return c;
}
//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
if (getPoint(x,y)==o)
{
putPoint(x,y,c);
fill(x+1,y,c,o);
fill(x-1,y,c,o);
fill(x,y+1,c,o);
fill(x,y-1,c,o);
}
}
//Gib display aus
void display (void)
{
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
printf("%c",screen[j][i]);
}
printf("\n");
}
}
#define HEIGHT 20
#define WIDTH 15
extern void clear(char c);
extern void fill(int x, int y, char c, char o);
extern void putPoint(int x, int y, char c);
extern char getPoint(int x, int y);
extern void display(void);
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "stack.h"
char screen[WIDTH][HEIGHT];
//Setze alle Einträge in display auf c
void clear (char c)
{
for (int i=0;i<WIDTH;i++)
{
for (int j=0;j<HEIGHT;j++)
{
screen[i][j]=c;
}
}
}
//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
screen[x][y]=c;
}
//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
char c=screen[x][y];
return c;
}
//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
push (x, y);
while (!stack_empty ())
{
pop (&x, &y);
if (getPoint (x, y) == o)
{
putPoint (x, y, c++);
push (x + 1, y);
push (x - 1, y);
push (x, y + 1);
push (x, y - 1);
}
}
}
//Gib display aus
void display (void)
{
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
printf("%c",screen[j][i]);
}
printf("\n");
}
}
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>
char screen[WIDTH][HEIGHT];
//Setze alle Einträge in display auf c
void clear (char c)
{
for (int i=0;i<WIDTH;i++)
{
for (int j=0;j<HEIGHT;j++)
{
screen[i][j]=c;
}
}
}
//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
screen[x][y]=c;
}
//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
char c=screen[x][y];
return c;
}
//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
if (getPoint(x,y)==o)
{
putPoint(x,y,c);
fill(x+1,y,c,o);
fill(x-1,y,c,o);
fill(x,y+1,c,o);
fill(x,y-1,c,o);
}
}
//Gib display aus
void display (void)
{
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
printf("%c",screen[j][i]);
}
printf("\n");
}
}
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>
char screen[WIDTH][HEIGHT];
//Setze alle Einträge in display auf c
void clear (char c)
{
for (int i=0;i<WIDTH;i++)
{
for (int j=0;j<HEIGHT;j++)
{
screen[i][j]=c;
}
}
}
//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
screen[x][y]=c;
}
//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
char c=screen[x][y];
return c;
}
//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
if (getPoint(x,y)==o)
{
putPoint(x,y,c);
fill(x+1,y,c,o);
fill(x-1,y,c,o);
fill(x,y+1,c,o);
fill(x,y-1,c,o);
}
}
//Gib display aus
void display (void)
{
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
printf("%c",screen[i][j]);
}
printf("\n");
}
}
#define HEIGHT 5
#define WIDTH 10
extern void clear(char c);
extern void fill(int x, int y, char c, char o);
extern void putPoint(int x, int y, char c);
extern char getPoint(int x, int y);
extern void display(void);
while true; do clear; ./test; sleep 1; clear; ./test-pg; sleep 1; done
#include "stack.h"
typedef struct
{
int x, y;
}
coordinate;
coordinate stack[STACK_SIZE];
int stack_pointer = 0;
int stack_empty (void)
{
return !stack_pointer;
}
void fatal_error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
void push (int x, int y)
{
if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
fatal_error ("stack overflow");
else
{
stack[stack_pointer].x = x;
stack[stack_pointer].y = y;
stack_pointer++;
}
}
void pop (int *x, int *y)
{
if (stack_pointer < 1 || stack_pointer > STACK_SIZE)
fatal_error ("stack underflow");
else
{
--stack_pointer;
*x = stack[stack_pointer].x;
*y = stack[stack_pointer].y;
}
}
void dump (void)
{
if (stack_pointer < 0)
fatal_error ("stack underflow");
else if (stack_pointer >= STACK_SIZE)
fatal_error ("stack overflow");
else if (stack_pointer == 0)
printf ("stack is empty\n");
else
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" (%d,%d)", stack[i].x, stack[i].y);
printf ("\n");
}
}
#include <stdio.h>
#include <stdlib.h>
#define STACK_SIZE (7 * 42)
extern int stack_empty (void);
extern void push (int x, int y);
extern void pop (int *x, int *y);
extern void dump (void);
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>
int main (void)
{
clear ('.');
putPoint (3, 1, '*');
display ();
return 0;
}
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>
int main (void)
{
clear ('.');
putPoint (10, 1, '*');
display ();
return 0;
}
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>
int main (void)
{
clear ('.');
putPoint (3, 6, '*');
display ();
return 0;
}
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
int main (void)
{
clear ('.');
for (int i = 3; i < 13; i++)
putPoint (i, 3, '*');
for (int j = 4; j < 11; j++)
putPoint (2, j, '*');
putPoint (13, 4, '*');
putPoint (12, 5, '*');
putPoint (12, 6, '*');
putPoint (13, 7, '*');
putPoint (14, 8, '*');
putPoint (14, 9, '*');
putPoint (13, 10, '*');
for (int i = 3; i < 13; i++)
putPoint (i, 11, '*');
fill (5, 5, '%', '.');
display ();
return 0;
}
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
int main (void)
{
clear ('.');
for (int i = 3; i < 13; i++)
putPoint (i, 3, '*');
for (int j = 4; j < 11; j++)
putPoint (2, j, '*');
putPoint (13, 4, '*');
putPoint (12, 5, '*');
putPoint (12, 6, '*');
putPoint (13, 7, '*');
putPoint (14, 8, '*');
putPoint (14, 9, '*');
putPoint (13, 10, '*');
for (int i = 3; i < 13; i++)
putPoint (i, 11, 'A');
fill (5, 5, '%', '.');
display ();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment