-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.c
More file actions
77 lines (66 loc) · 1.16 KB
/
menu.c
File metadata and controls
77 lines (66 loc) · 1.16 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
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
#include "header.h"
#include <stdlib.h>
#include <stdio.h>
int ask(const char *msgs[], int n)
{
// system("clear");
int choice = -1;
char *err = "";
while (choice < 0 || choice >= n)
{
puts(err);
err = "Wrong input";
for (int i = 0; i < n; i++)
{
printf("%s\n", msgs[i]);
}
printf("Enter option: ");
scanf("%d", &choice);
}
if (!choice)
choice -= 20;
return choice;
}
void menu(String* Str)
{
const char *MSGS_MAIN[] = {
"0. Quit",
"1. Input with keyboard",
"2. Concatenate",
"3. Get substring from i to j",
"4. Split into words",
"5. Print out"
};
const int MAIN_NMEMB = 6;
int option = 0;
while (option >= 0)
{
switch (option)
{
case 0:
option = ask(MSGS_MAIN, MAIN_NMEMB);
break;
case 1:
Str->Info->keyboardInput(Str);
option = 0;
break;
case 2:
Str->Info->concatenate(Str);
option = 0;
break;
case 3:
Str->Info->getSubString(Str);
option = 0;
break;
case 4:
Str->Info->splitIntoWords(Str);
option = 0;
break;
case 5:
Str->Info->print(Str);
option = 0;
default:
option = 0;
}
}
}