blob: c0273a4652f3505ccaad9c3a3f6241cef2b5de3d (
plain) (
blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char *name;
struct list_elem elem;
};
// Read a line from stdin, strip the eventual newline and return a pointer
// to the string. Remember to free the pointer.
char *read_input() {
char *buf = NULL;
size_t buf_size = 0;
size_t read = getline(&buf, &buf_size, stdin);
if (read == -1) {
free(buf);
buf = NULL;
} else if (read >= 1 && buf[read - 1] == '\n') {
buf[read - 1] = '\0';
}
return buf;
}
int read_int() {
char *buf = read_input();
int res = -1;
if (!buf) {
printf("Failed to read int from stdin\n");
} else {
res = atoi(buf);
}
free(buf);
return res;
}
void insert (struct list *student_list) {
}
void delete (struct list *student_list) {
}
void list (struct list *student_list) {
}
void quit (struct list *student_list) {
}
int main() {
struct list student_list;
list_init (&student_list);
int opt;
do {
printf("Menu:\n");
printf("1 - Insert student\n");
printf("2 - Delete student\n");
printf("3 - List students\n");
printf("4 - Exit\n");
switch (read_int()) {
case 1:
{
insert(&student_list);
break;
}
case 2:
{
delete(&student_list);
break;
}
case 3:
{
list(&student_list);
break;
}
case 4:
{
quit(&student_list);
break;
}
default:
{
printf("Quit? (1/0):\n");
if (read_int())
quit(&student_list);
break;
}
}
} while(1);
return 0;
}
|