a5.2
This commit is contained in:
parent
1bb6566851
commit
e0f2a67666
|
@ -0,0 +1,52 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define NUM_ANGESTELLTE 10
|
||||||
|
|
||||||
|
#define NAME_LEN 40
|
||||||
|
typedef struct {
|
||||||
|
char name[NAME_LEN+1];
|
||||||
|
int personalnummer;
|
||||||
|
float gehalt;
|
||||||
|
} angestellter;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int anzahl;
|
||||||
|
|
||||||
|
angestellter *array[NUM_ANGESTELLTE];
|
||||||
|
|
||||||
|
for (int i = 0; i < NUM_ANGESTELLTE; i++) {
|
||||||
|
array[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int input = 0;
|
||||||
|
while (1) {
|
||||||
|
scanf("%d", &input);
|
||||||
|
if (input >= NUM_ANGESTELLTE || input < 0) break;
|
||||||
|
|
||||||
|
if (array[input] == NULL) {
|
||||||
|
array[input] = (angestellter*)malloc(sizeof(angestellter));
|
||||||
|
printf("Name: ");
|
||||||
|
scanf("%s", array[input]->name);
|
||||||
|
|
||||||
|
printf("Personalnummer: ");
|
||||||
|
scanf("%d", &array[input]->personalnummer);
|
||||||
|
|
||||||
|
printf("Gehalt: ");
|
||||||
|
scanf("%f", &array[input]->gehalt);
|
||||||
|
} else {
|
||||||
|
free(array[input]);
|
||||||
|
array[input] = NULL;
|
||||||
|
}
|
||||||
|
printf("\n############\nAngestellte:\n------------\n");
|
||||||
|
for (int i = 0; i < NUM_ANGESTELLTE; i++) {
|
||||||
|
if (array[i] == NULL) {
|
||||||
|
printf("%d: ---\n", i);
|
||||||
|
} else {
|
||||||
|
printf("%d: %s | %d | %f\n", i, array[i]->name, array[i]->personalnummer, array[i]->gehalt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue