i create program that create menu and sub-menu
user have the ability to move up and down in parent menu and only have the ability to move down in sub-menu
the problem that when user navigate through sub-menu down the sub-menu disappear and i do not want that any solution i now it is easy with functions to create but i need it without function my code
user have the ability to move up and down in parent menu and only have the ability to move down in sub-menu
the problem that when user navigate through sub-menu down the sub-menu disappear and i do not want that any solution i now it is easy with functions to create but i need it without function my code
Code:
#define ENTER 13
#define ESCAP 27
#define HOME 71
#define UP 72
#define DOWN 80
#define END 79
#define TAB 9
#include<conio.h>
#include<stdio.h>
int main()
{
char ch,names[3][10]={"new","display","exit"},newMenu[3][10]={"file","proper","edit"};
int i,flag=0,pos=0,subpos=0,j;
do{
clrscr();
for(i=0;i<3;i++)
{
gotoxy(5,i+1);
if(i==pos)
textattr(0x70+BLINK);
cprintf("%s",names[i]);
textattr(0x07);
}
ch=getch();
switch(ch)
{
case ENTER:
switch(pos)
{
case 0:
case 1:
clrscr();
printf("%s \t press any key to return main menu",names[pos]);
ch=getch();
break;
case 2:
flag=1;
break;
}
break;
case ESCAP:
flag=1;
break;
case TAB:
pos++;
if(pos >2)
pos=0;
break;
case NULL:
ch=getch();
switch(ch)
{
case HOME: //home
pos=0;
break;
case UP: //up
pos--;
if(pos<0)
pos=2;
break;
case DOWN:
pos++;
if(pos>2)
pos=0;
break;
case END:
pos=2;
break;
case 77: //right arrow
switch(pos)
{
case 0: //new highlted
do{
for(j=0;j<3;j++){
gotoxy(13,j+2);
if(subpos == j)
textattr(RED+BLINK);
cprintf("%s",newMenu[j]);
textattr(WHITE);
}//end for
ch=getch();
switch(ch)
{
case NULL:
ch=getch();
switch(ch)
{
case DOWN:
subpos++;
if(subpos == 2)
subpos = 0;
break;
}
break;//end null case
}//end switch ch 2nd step of coposite
break;//end case 0
}while(1);
}//end switch pos
break; //end Null case
}//end switch
break; // end case 77
default :
flag = 1;
break;
}
}while(flag == 0);
return 0;
}
Comment