How to write a C Program Menu Test (Modified) in C Programming Language ?
#include <ncurses.h>
#define MENUMAX 6
void drawmenu(int item)
{
int c;
char mainmenutitle[] = "Systems Administration"; // Title
char subtitle[] = "Please move the cursor to the desired item and press Enter";
char menu [MENUMAX] [21] = { /* 6 Items for MENUMAX */
"View processes",
"User and Security",
"Word Processing",
"Finanacle Managment",
"Maintence",
"Shutdown"
};
clear();
/* Print Title and Subtitle */
mvaddstr(1, 26, mainmenutitle);
mvaddstr(3,1, subtitle);
/* Menu Items print and highlight */
for (c=0;c<MENUMAX;c++)
{
if (c==item)
attron(A_REVERSE); // Highlight
mvaddstr(5+(c*1),5,menu[c]);
attroff(A_REVERSE);
}
/* Bottom Part of the Menu */
attron(A_BOLD);
mvaddstr(19,2, "F1=Help F2=Refresh F9=Shell Enter=Do");
attroff(A_BOLD);
refresh();
}
int main(void)
{
int key,menuitem;
menuitem = 0;
initscr();
refresh();
drawmenu(menuitem);
keypad(stdscr,TRUE);
noecho(); /* Disable Echo */
do
{
key = getch();
switch(key)
{
case KEY_DOWN:
menuitem++;
if(menuitem > MENUMAX-1) menuitem = 0;
break;
case KEY_UP:
menuitem--;
if(menuitem < 0) menuitem = MENUMAX-1;
break;
default:
break;
}
drawmenu(menuitem);
} while(key != '\n');
echo(); /* Turn on Echo */
/* At this point, the value of selected menu is kept in the menuitem
* varible. The program can branch off to whatever subroutine
* is required to carry out that function */
endwin();
return 0;
}
#define MENUMAX 6
void drawmenu(int item)
{
int c;
char mainmenutitle[] = "Systems Administration"; // Title
char subtitle[] = "Please move the cursor to the desired item and press Enter";
char menu [MENUMAX] [21] = { /* 6 Items for MENUMAX */
"View processes",
"User and Security",
"Word Processing",
"Finanacle Managment",
"Maintence",
"Shutdown"
};
clear();
/* Print Title and Subtitle */
mvaddstr(1, 26, mainmenutitle);
mvaddstr(3,1, subtitle);
/* Menu Items print and highlight */
for (c=0;c<MENUMAX;c++)
{
if (c==item)
attron(A_REVERSE); // Highlight
mvaddstr(5+(c*1),5,menu[c]);
attroff(A_REVERSE);
}
/* Bottom Part of the Menu */
attron(A_BOLD);
mvaddstr(19,2, "F1=Help F2=Refresh F9=Shell Enter=Do");
attroff(A_BOLD);
refresh();
}
int main(void)
{
int key,menuitem;
menuitem = 0;
initscr();
refresh();
drawmenu(menuitem);
keypad(stdscr,TRUE);
noecho(); /* Disable Echo */
do
{
key = getch();
switch(key)
{
case KEY_DOWN:
menuitem++;
if(menuitem > MENUMAX-1) menuitem = 0;
break;
case KEY_UP:
menuitem--;
if(menuitem < 0) menuitem = MENUMAX-1;
break;
default:
break;
}
drawmenu(menuitem);
} while(key != '\n');
echo(); /* Turn on Echo */
/* At this point, the value of selected menu is kept in the menuitem
* varible. The program can branch off to whatever subroutine
* is required to carry out that function */
endwin();
return 0;
}