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

Vorbereitung 22.1.2018

parent ddbbe981
No related branches found
No related tags found
No related merge requests found
Showing with 563 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
char **new_name = malloc (4 * sizeof (char *));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
free (name);
name = new_name;
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
char **new_name = malloc (4 * sizeof (char *));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
name = new_name;
free (name);
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
char **new_name = malloc (4 * sizeof (char *));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
name = new_name;
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
free (new_name);
return 0;
}
#include <stdio.h>
#define STACK_SIZE 10
int stack[STACK_SIZE];
int stack_pointer = 0;
void push (int x)
{
stack[stack_pointer++] = x;
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack content:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
if (stack_pointer)
printf ("\n");
else
printf (" (empty)\n");
}
void insert (int x, int pos)
{
for (int i = pos; i < stack_pointer; i++)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
void insert_sorted (int x)
{
int i = 0;
while (i < stack_pointer && x < stack[i])
i++;
insert (x, i);
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
insert (5, 1);
show ();
insert_sorted (42);
show ();
insert_sorted (2);
show ();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
free (name);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
char **new_name = malloc (4 * sizeof (char *));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
free (name);
name = new_name;
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
char **new_name = malloc (4 * sizeof (char *));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
name = new_name;
free (name);
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char **name = malloc (3 * sizeof (char *));
name[0] = "Anton";
name[1] = "Berthold";
name[2] = "Caesar";
for (int i = 0; i < 3; i++)
printf ("%s\n", name[i]);
char **new_name = malloc (4 * sizeof (char *));
for (int i = 0; i < 3; i++)
new_name[i] = name[i];
name = new_name;
name[3] = "Dieter";
for (int i = 0; i < 4; i++)
printf ("%s\n", name[i]);
free (name);
free (new_name);
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void push (int x)
{
fifo[fifo_pointer++] = x;
}
int pop (void)
{
return fifo[0];
for (int i = 1; i < fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void push (int x)
{
fifo[fifo_pointer++] = x;
}
int pop (void)
{
int result = fifo[0];
for (int i = 1; i < fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_pointer = 0;
void push (int x)
{
fifo[fifo_pointer++] = x;
}
int pop (void)
{
int result = fifo[0];
for (int i = 1; i != fifo_pointer; i++)
fifo[i - 1] = fifo[i];
fifo_pointer--;
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
}
int pop (void)
{
int result = fifo[fifo_read++];
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 5
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
}
int pop (void)
{
int result = fifo[fifo_read++];
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
push (256);
push (42);
push (1117);
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 5
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
}
int pop (void)
{
int result = fifo[fifo_read++];
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
for (int i = 0; i < 1000; i++)
{
push (i);
printf ("%d\n", pop ());
}
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
fifo[fifo_write++] = x;
if (fifo_write >= FIFO_SIZE)
fifo_write = 0;
}
int pop (void)
{
int result = fifo[fifo_read++];
if (fifo_read >= FIFO_SIZE)
fifo_read = 0;
return result;
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
for (int i = 0; i < 1000; i++)
{
push (i);
printf ("%d\n", pop ());
}
return 0;
}
#include <stdio.h>
#define FIFO_SIZE 10
int fifo[FIFO_SIZE];
int fifo_read = 0;
int fifo_write = 0;
void push (int x)
{
if ((fifo_write + 1) % FIFO_SIZE == fifo_read)
fprintf (stderr, "push(): FIFO is full\n");
else
{
fifo[fifo_write++] = x;
if (fifo_write >= FIFO_SIZE)
fifo_write = 0;
}
}
int pop (void)
{
if (fifo_read == fifo_write)
{
fprintf (stderr, "pop(): FIFO is empty\n");
return -1;
}
else
{
int result = fifo[fifo_read++];
if (fifo_read >= FIFO_SIZE)
fifo_read = 0;
return result;
}
}
int main (void)
{
push (3);
push (7);
push (137);
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
printf ("%d\n", pop ());
for (int i = 0; i < 15; i++)
push (i);
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (window), vbox);
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_add (GTK_CONTAINER (vbox), button);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (vbox), drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment