-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_ex1.c
52 lines (43 loc) · 1.02 KB
/
struct_ex1.c
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
48
49
50
51
52
#include <stdio.h>
struct school *returnStructPt(struct school);
struct students {
char *name;
int age;
};
struct school {
int n_classes;
struct students st[10];
};
int main () {
int i = 0;
struct school sc1;
// Back to school
while (i++ < 2) { // School not full
printf("Enroll student \t %d\n", (i - 1));
int j = 0;
sc1.st[i-1].name = malloc(20);
if (sc1.st[i-1].name == NULL) { printf("Malloc Err");return 0; }
while((sc1.st[i-1].name[j++] = getchar()) != '\n')
// putchar(sc1.st[i-1].name[j - 1]);
;
sc1.st[i-1].name[j+1] = '\0';
//sc1.st[i-1].name = buff;
}
printf("School is full with %d students\n", --i);
char c;
//printf();
while((c = getchar()) != 'p')
;
while (i-- > 0) {
printf("Studentul %d : %s \n", i, sc1.st[i].name);
}
struct school *pointer_to_school;
pointer_to_school = returnStructPt(sc1);
printf("Printf %s", pointer_to_school->st[1].name);
return 1;
}
struct school *returnStructPt(struct school sc) {
struct school *ptr_sc = 0;
ptr_sc = ≻
return ptr_sc;
}