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

Beispielprogramme 14.1.2016

parent b0dfbfc5
Branches
No related tags found
No related merge requests found
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { &i, &s };
return 0;
}
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s };
return 0;
}
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s };
for (int i = 0; i < 2; i++)
if (object[i]->type == 1)
printf ("Integer: %d\n", object[i]->content);
else if (object[i]->type == 2)
printf ("String: \"%s\"\n", object[i]->content);
return 0;
}
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s };
for (int i = 0; i < 2; i++)
if (object[i]->type == 1)
printf ("Integer: %d\n", (t_integer *) object[i]->content);
else if (object[i]->type == 2)
printf ("String: \"%s\"\n", (t_string *) object[i]->content);
return 0;
}
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s };
for (int i = 0; i < 2; i++)
if (object[i]->type == 1)
printf ("Integer: %d\n", ((t_integer *) object[i])->content);
else if (object[i]->type == 2)
printf ("String: \"%s\"\n", ((t_string *) object[i])->content);
return 0;
}
#include <stdio.h>
typedef struct
{
int type;
} t_base;
typedef struct
{
int type;
int content;
} t_integer;
typedef struct
{
int type;
char *content;
} t_string;
int main (void)
{
t_integer i = { 1, 42 };
t_string s = { 2, "Hello, world!" };
t_base *object[] = { (t_base *) &i, (t_base *) &s };
for (int i = 0; i < 2; i++)
if (object[i]->type == 2)
printf ("Integer: %d\n", ((t_integer *) object[i])->content);
else if (object[i]->type == 1)
printf ("String: \"%s\"\n", ((t_string *) object[i])->content);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment