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

Skript: Links angepaßt

parent b48b1054
No related branches found
No related tags found
No related merge requests found
GNU/Linux
~~~~~~~~~
Compilieren: gcc -Wall -O cube-5.c opengl-magic.c \
-lGL -lGLU -lglut -o cube-5
Aufrufen: ./cube-5
MacOS
~~~~~
Compilieren: gcc -Wall -O cube-5.c opengl-magic.c \
-framework OpenGL -framework GLUT -o cube-5
Aufrufen: ./cube-5
Cygwin mit X11
~~~~~~~~~~~~~~
Compilieren: gcc -Wall -O cube-5.c opengl-magic.c \
-lGL -lGLU -lglut -o cube-5
Aufrufen: DISPLAY=:0.0 ./cube-5
oder:
einmalig: export DISPLAY=:0.0
danach: ./cube-5
Vorher einmalig: X-Server starten
XWin -multiwindow &
Cygwin ohne X11
~~~~~~~~~~~~~~~
Compilieren: i686-pc-mingw32-gcc -I freeglut/include -L freeglut/lib \
-Wall -O cube-5.c opengl-magic.c \
-lOpenGL32 -lGLU32 -lfreeglut -o cube-5
Aufrufen: ./cube-5
MinGW ohne X11
~~~~~~~~~~~~~~
Compilieren: gcc -I freeglut/include -L freeglut/lib \
-Wall -O cube-5.c opengl-magic.c \
-lOpenGL32 -lGLU32 -lfreeglut -o cube-5
Aufrufen: ./cube-5
#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;
}
#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 (drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 };
GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 };
GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 };
gdk_cairo_set_source_rgba (c, &red);
cairo_rectangle (c, 10, 10, 60, 40);
cairo_fill (c);
gdk_cairo_set_source_rgba (c, &yellow);
cairo_arc (c, 65, 50, 30, 0, 2 * G_PI);
cairo_fill (c);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, 10, 70);
cairo_line_to (c, 70, 70);
cairo_line_to (c, 40, 18);
cairo_close_path (c);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
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);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
gtk_widget_set_size_request (drawing_area, 100, 100);
gtk_widget_show (drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <stdio.h>
#include <gtk/gtk.h>
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 };
GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 };
GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 };
gdk_cairo_set_source_rgba (c, &red);
cairo_rectangle (c, 10, 10, 60, 40);
cairo_fill (c);
gdk_cairo_set_source_rgba (c, &yellow);
cairo_arc (c, 65, 50, 30, 0, 2 * G_PI);
cairo_fill (c);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, 10, 70);
cairo_line_to (c, 70, 70);
cairo_line_to (c, 40, 18);
cairo_close_path (c);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean button_press (GtkWidget *widget, GdkEventButton *e, gpointer data)
{
printf ("button %d pressed at (%lf, %lf)\n", e->button, e->x, e->y);
return FALSE;
}
gboolean key_press (GtkWidget *widget, GdkEventKey *e, gpointer data)
{
printf ("key '%c' (%d) pressed\n", e->keyval, e->keyval);
return FALSE;
}
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);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
gtk_widget_set_size_request (drawing_area, 100, 100);
gtk_widget_add_events (drawing_area, GDK_BUTTON_PRESS_MASK);
g_signal_connect (drawing_area, "button_press_event", G_CALLBACK (button_press), NULL);
gtk_widget_add_events (window, GDK_KEY_PRESS_MASK);
g_signal_connect (window, "key_press_event", G_CALLBACK (key_press), NULL);
gtk_widget_show (drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
No preview for this file type
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
union t_object;
typedef struct
{
void (* print) (union t_object *this);
} t_base;
typedef struct
{
void (* print) (union t_object *this);
int content;
} t_integer;
typedef struct
{
void (* print) (union t_object *this);
char *content;
} t_string;
typedef union t_object
{
t_base base;
t_integer integer;
t_string string;
} t_object;
void print_integer (t_object *this)
{
printf ("Integer: %d\n", this->integer.content);
}
void print_string (t_object *this)
{
printf ("String: \"%s\"\n", this->string.content);
}
t_object *new_integer (int i)
{
t_object *p = malloc (sizeof (t_integer));
p->integer.print = print_integer;
p->integer.content = i;
return p;
}
t_object *new_string (char *s)
{
t_object *p = malloc (sizeof (t_string));
p->string.print = print_string;
p->string.content = s;
return p;
}
int main (void)
{
t_object *object[] = { new_integer (42),
new_string ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->base.print (object[i]);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
union t_object;
struct t_vmt;
typedef struct
{
struct t_vmt *vmt;
} t_base;
typedef struct
{
struct t_vmt *vmt;
int content;
} t_integer;
typedef struct
{
struct t_vmt *vmt;
char *content;
} t_string;
typedef union t_object
{
t_base base;
t_integer integer;
t_string string;
} t_object;
typedef struct t_vmt
{
void (* print) (union t_object *this);
} t_vmt;
void print_integer (t_object *this)
{
printf ("Integer: %d\n", this->integer.content);
}
void print_string (t_object *this)
{
printf ("String: \"%s\"\n", this->string.content);
}
t_vmt vmt_integer = { print_integer };
t_vmt vmt_string = { print_string };
t_object *new_integer (int i)
{
t_object *p = malloc (sizeof (t_integer));
p->integer.vmt = &vmt_integer;
p->integer.content = i;
return p;
}
t_object *new_string (char *s)
{
t_object *p = malloc (sizeof (t_string));
p->integer.vmt = &vmt_string;
p->string.content = s;
return p;
}
int main (void)
{
t_object *object[] = { new_integer (42),
new_string ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->base.vmt->print (object[i]);
return 0;
}
#include <stdio.h>
struct TBase
{
virtual void print () = 0;
};
struct TInteger: TBase
{
int content;
virtual void print ();
TInteger (int i);
};
struct TString: TBase
{
char *content;
virtual void print ();
TString (char *s);
};
void TInteger::print ()
{
printf ("Integer: %d\n", content);
}
void TString::print ()
{
printf ("String: \"%s\"\n", content);
}
TInteger::TInteger (int i)
{
content = i;
}
TString::TString (char *s)
{
content = s;
}
int main (void)
{
TBase *object[] = { new TInteger (42),
new TString ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
object[i]->print ();
return 0;
}
#include <stdio.h>
#define T_BASE 0
#define T_INTEGER 1
#define T_STRING 2
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
void print_object (t_base *this)
{
if (this->type == T_INTEGER)
printf ("Integer: %d\n", ((t_integer *) this)->content);
else if (this->type == T_STRING)
printf ("String: \"%s\"\n", ((t_string *) this)->content);
}
int main (void)
{
t_integer i = { T_INTEGER, 42 };
t_string s = { T_STRING, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s, NULL };
for (int i = 0; object[i]; i++)
print_object (object[i]);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define T_BASE 0
#define T_INTEGER 1
#define T_STRING 2
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
void print_object (t_base *this)
{
if (this->type == T_INTEGER)
printf ("Integer: %d\n", ((t_integer *) this)->content);
else if (this->type == T_STRING)
printf ("String: \"%s\"\n", ((t_string *) this)->content);
}
t_integer *new_integer (int i)
{
t_integer *p = malloc (sizeof (t_integer));
p->type = T_INTEGER;
p->content = i;
return p;
}
t_string *new_string (char *s)
{
t_string *p = malloc (sizeof (t_string));
p->type = T_STRING;
p->content = s;
return p;
}
int main (void)
{
t_base *object[] = { (t_base *) new_integer (42),
(t_base *) new_string ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
print_object (object[i]);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define T_BASE 0
#define T_INTEGER 1
#define T_STRING 2
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
typedef union
{
t_base base;
t_integer integer;
t_string string;
} t_object;
void print_object (t_object *this)
{
if (this->base.type == T_INTEGER)
printf ("Integer: %d\n", this->integer.content);
else if (this->base.type == T_STRING)
printf ("String: \"%s\"\n", this->string.content);
}
t_object *new_integer (int i)
{
t_object *p = malloc (sizeof (t_integer));
p->integer.type = T_INTEGER;
p->integer.content = i;
return p;
}
t_object *new_string (char *s)
{
t_object *p = malloc (sizeof (t_string));
p->string.type = T_STRING;
p->string.content = s;
return p;
}
int main (void)
{
t_object *object[] = { new_integer (42),
new_string ("Hello, world!"),
NULL };
for (int i = 0; object[i]; i++)
print_object (object[i]);
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;
}
void push_at (int x, int pos)
{
for (int i = stack_pointer - 1; i >= pos; i--)
stack[i + 1] = stack[i];
stack[pos] = x;
stack_pointer++;
}
void push_sorted (int x)
{
int left = 0;
int right = stack_pointer;
while (left < right - 1)
{
int i = (left + right) / 2;
if (x < stack[i])
right = i;
else
left = i;
}
push_at (x, right);
}
int pop (void)
{
return stack[--stack_pointer];
}
void show (void)
{
printf ("stack:");
for (int i = 0; i < stack_pointer; i++)
printf (" %d", stack[i]);
printf ("\n");
}
int main (void)
{
push (3);
push (7);
push (137);
show ();
push_sorted (5);
show ();
push_sorted (256);
show ();
push_sorted (42);
push_sorted (13);
push_sorted (107);
show ();
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char hello[] = "Hello, world!\n";
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
printf ("%s\n", hello + 7);
printf ("%zd\n", strlen (hello + 7));
hello[5] = 0;
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char *anton = "Anton";
char *zacharias = "Zacharias";
printf ("%d\n", strcmp (anton, zacharias));
printf ("%d\n", strcmp (zacharias, anton));
printf ("%d\n", strcmp (anton, anton));
char buffer[100] = "Huber ";
strcat (buffer, anton);
printf ("%s\n", buffer);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment