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

Weitere Beispiele zur "Tier-Datenbank"-Aufgabe

parent 969a6fab
Branches
No related tags found
No related merge requests found
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int wings;
} with_wings;
typedef struct with_legs
{
int legs;
} with_legs;
int main (void)
{
animal *a[2];
animal duck;
a[0] = &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
animal cow;
a[1] = &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
int legs;
} with_legs;
int main (void)
{
animal *a[2];
animal duck;
a[0] = &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
animal cow;
a[1] = &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
int dummy; /* 64-Bit-Alignment */
char *name;
} animal;
typedef struct with_wings
{
int type;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
int legs;
} with_legs;
int main (void)
{
animal *a[2];
animal duck;
a[0] = &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
animal cow;
a[1] = &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
char *name;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
char *name;
int legs;
} with_legs;
int main (void)
{
animal *a[2];
animal duck;
a[0] = &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
animal cow;
a[1] = &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
char *name;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
char *name;
int legs;
} with_legs;
int main (void)
{
animal *a[2];
with_wings duck;
a[0] = &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
with_legs cow;
a[1] = &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
char *name;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
char *name;
int legs;
} with_legs;
int main (void)
{
animal *a[2];
with_wings duck;
a[0] = (with_wings *) &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
with_legs cow;
a[1] = (with_legs *) &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef union object
{
animal a;
with_wings w;
with_legs l;
} object;
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
char *name;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
char *name;
int legs;
} with_legs;
int main (void)
{
animal *a[2];
with_wings duck;
a[0] = (with_wings *) &duck;
printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
a[0]->name = "duck";
printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings);
with_legs cow;
a[1] = (with_legs *) &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
printf ("a[%d]->type = %d\n", i, a[i]->type);
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
char *name;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
char *name;
int legs;
} with_legs;
typedef union object
{
animal a;
with_wings w;
with_legs l;
} object;
int main (void)
{
animal *a[2];
with_wings duck;
a[0] = (animal *) &duck;
a[0]->type = WITH_WINGS;
a[0]->name = "duck";
((with_wings *) a[0])->wings = 2;
with_legs cow;
a[1] = (animal *) &cow;
a[1]->type = WITH_LEGS;
a[1]->name = "cow";
((with_legs *) a[1])->legs = 4;
for (int i = 0; i < 2; i++)
{
if (a[i]->type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs);
else if (a[i]->type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings);
else
printf ("Error in animal: %s\n", a[i]->name);
}
return 0;
}
#include <stdio.h>
#define ANIMAL 0
#define WITH_WINGS 1
#define WITH_LEGS 2
typedef struct animal
{
int type;
char *name;
} animal;
typedef struct with_wings
{
int type;
char *name;
int wings;
} with_wings;
typedef struct with_legs
{
int type;
char *name;
int legs;
} with_legs;
typedef union object
{
animal a;
with_wings w;
with_legs l;
} object;
int main (void)
{
object *a[2];
object duck;
a[0] = &duck;
a[0]->a.type = WITH_WINGS;
a[0]->a.name = "duck";
a[0]->w.wings = 2;
object cow;
a[1] = &cow;
a[1]->a.type = WITH_LEGS;
a[1]->a.name = "cow";
a[1]->l.legs = 4;
for (int i = 0; i < 2; i++)
{
if (a[i]->a.type == WITH_LEGS)
printf ("A %s has %d legs.\n", a[i]->a.name, a[i]->l.legs);
else if (a[i]->a.type == WITH_WINGS)
printf ("A %s has %d wings.\n", a[i]->a.name, a[i]->w.wings);
else
printf ("Error in animal: %s\n", a[i]->a.name);
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment