-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuimain.c
44 lines (39 loc) · 1.05 KB
/
uimain.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
#include <stdio.h>
#include "draw.h" // project-related declarations
int main()
{
puts("Welcome!");
while (1) { // Infinite while loop
fputs("Select which shape you want to print (Triangle = t, Square = s, Chars = c) or 'q' to quit\n> ", stdout);
fflush(stdout); /* stdout only flushes automatically on \n */
int c;
while ((c = getchar()) == '\n'); /* ignore newlines */
if (c == EOF) /* terminate on end-of-file */
goto done;
// Given the user answer, select which method to call
switch (c) {
case 't':
puts("You selected triangle:");
print_triangle(5, 7);
break;
case 's':
puts("You selected square:");
print_square(5, 5);
break;
case 'c':
puts("You selected chars:");
for (char c = 'a'; c < 'd'; c++)
print_char_5x7(c);
break;
case 'q':
puts("Bye!");
goto done; /* terminate */
case '\n':
break;
default:
printf("Unrecognized option '%c', please try again!\n", c);
}
}
done: // To exit from program
return 0;
}