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

Beispiele zur "Tier-Datenbank"-Aufgabe

parent de83fc1d
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;
a[0]->type = WITH_WINGS;
a[0]->name = "duck";
((with_wings *) a[0])->wings = 2;
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++)
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 wings;
} with_wings;
typedef struct with_legs
{
int legs;
} with_legs;
int main (void)
{
animal *a[2];
animal duck;
a[0] = &duck;
a[0]->type = WITH_WINGS;
a[0]->name = "duck";
((with_wings *) a[0])->wings = 2;
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[i]->type = %d\n", 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 wings;
} with_wings;
typedef struct with_legs
{
int legs;
} with_legs;
int main (void)
{
animal *a[2];
animal duck;
a[0] = &duck;
a[0]->type = WITH_WINGS;
a[0]->name = "duck";
((with_wings *) a[0])->wings = 2;
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[i]->type = %d\n", 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 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\n", a[0]->type);
a[0]->type = WITH_WINGS;
printf ("2: a[0]->type = %d\n", a[0]->type);
a[0]->name = "duck";
printf ("3: a[0]->type = %d\n", a[0]->type);
((with_wings *) a[0])->wings = 2;
printf ("4: a[0]->type = %d\n", a[0]->type);
animal cow;
printf ("5: a[0]->type = %d\n", a[0]->type);
a[1] = &cow;
printf ("6: a[0]->type = %d\n", a[0]->type);
a[1]->type = WITH_LEGS;
printf ("7: a[0]->type = %d\n", a[0]->type);
a[1]->name = "cow";
printf ("8: a[0]->type = %d\n", a[0]->type);
((with_legs *) a[1])->legs = 4;
printf ("9: a[0]->type = %d\n", a[0]->type);
for (int i = 0; i < 2; i++)
{
printf ("a[i]->type = %d\n", 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 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;
printf ("5: a[0]->type = %d\n", a[0]->type);
a[1] = &cow;
printf ("6: a[0]->type = %d\n", a[0]->type);
a[1]->type = WITH_LEGS;
printf ("7: a[0]->type = %d\n", a[0]->type);
a[1]->name = "cow";
printf ("8: a[0]->type = %d\n", a[0]->type);
((with_legs *) a[1])->legs = 4;
printf ("9: a[0]->type = %d\n", a[0]->type);
for (int i = 0; i < 2; i++)
{
printf ("a[i]->type = %d\n", 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment