-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct3.c
More file actions
47 lines (44 loc) · 1.14 KB
/
struct3.c
File metadata and controls
47 lines (44 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tstudent // Strukturtyp
{
char name[28+1]; //Strukturkomponenten
int matrNr;
float KlNote;
int BelegNote;
}tStud;
char vbuf[128];
void putStud(struct tstudent* s)
{
//printf("%-28s %07d %3.1f %d\n",(*s).name,(*s).matrNr,(*s).KlNote,(*s).BelegNote);
printf("%-28s %07d %3.1f %d\n",s->name,s->matrNr,s->KlNote,s->BelegNote);
}
struct tstudent getStud()
{
struct tstudent s;
printf("Name :"); fgets(s.name,28,stdin);s.name[strlen(s.name)-1]=0;
printf("MatrNr :"); fgets(vbuf,128,stdin); s.matrNr=atoi(vbuf);
s.KlNote=0.0; s.BelegNote=0;
return s;
}
int main()
{
int count=0;
tStud* pStuds;
pStuds=malloc(sizeof (tStud));
if(pStuds==NULL){printf("kein Speicher\n"); exit(1);}
while(1)
{
int i;
pStuds[count]=getStud(); count ++;
for (i=0;i<count;i++) putStud(pStuds+i);
printf("noch einen Studenten erfassen? (j/n):");
fgets(vbuf,128,stdin);
if(vbuf[0]=='n') break;
pStuds=realloc(pStuds,sizeof(tStud)*(count+1));
if(pStuds==NULL){printf("kein Speicher\n"); exit(1);}
}
free(pStuds);
return 0;
}