/
menu.c
executable file
·55 lines (48 loc) · 999 Bytes
/
menu.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
53
54
55
#include "menu.h"
#include <stdio.h>
#include <string.h>
#include <cctype>
Menu::Menu () { strcpy (MenuName,"MAIN MENU");}
void Menu::SetName(const char *NewName)
{
strncpy (MenuName,NewName,49);
}
void Menu::AddItem(MenuItem *TheItem)
{
MenuItems.push_back(TheItem);
}
int Menu::GetCount()
{
return MenuItems.size();
}
void Menu::displayMenu()
{
fprintf(stdout,"\n\n *** %s ***\n=====================\n\n",MenuName);
for (MenuItem *A : MenuItems)
{
fprintf(stdout,"%c) %s\n",A->GetLetter(),A->GetName());
}
}
void Menu::doMenu()
{
int quit=0;
int foundone=0;
while (quit ==0)
{
displayMenu();
fprintf(stdout,"\n\nEnter Choice: ");
fflush(stdout);
char buf[80];
fgets(buf, sizeof(buf), stdin);
char choice=buf[0];
//char choice=_getch();
//fprintf(stdout,"Char is %i\n",choice);
foundone=0;
for (MenuItem *m : MenuItems)
{
if (tolower(m->GetLetter()) == tolower(choice)) { quit=m->Run(); foundone=1; break; }
}
if (foundone == 0) { fprintf(stdout,"Invalid Option!\n"); }
}
return;
}