Thread: Help!!! Simple Menu Program

  1. #1
    ghofigjong
    Guest

    Help!!! Simple Menu Program

    Anyone pls help me, i'm just learning C and my professor gave me a project. To make a simple Menu using only stdio.h, How do I input the Arrow Keys? Please Help

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Are you sure they wanted you to make a menu you use arrows with?? Wouldn't a simple:

    1. Option one
    2. Option two
    3. Option three

    Choice>

    Work?

  3. #3
    ghofigjong
    Guest

    Unhappy No they won't

    My professor said I should use Arrow keys like this:

    (The All Caps for example is the higlighted option)
    OPTION1 option2 option3

    when i press right option2 will be highlighted using cprintf and so on which ever choice i have selected till I press enter.

    option1 OPTION2 option3

    I think it has to do with ASCII codes or something

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    You could find the ascii value for the arrow keys, then have a variable for storing which one is highlighted (choice), and re-print the choices each time you push the arrow keys, with the right choice being highlighted.

    Code:
    main
    {
    int choice=1, buff;
    
    printf("CHOICE 1  choice 2  choice 3");
    for(buff=getch()!='ENTER')
    {
      if(buff=='LEFT ARROW')
      choice++
    }
    with that as a small example. Then for choice==1 print "choice 1 CHOICE 2 choice 3" etc.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Draco, I sure hope that's pseudo code
    >>for(buff=getch()!='ENTER')
    eh?

    Also, getch() is still non-standard C.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    yes, it is pseudo code. I'm a believer in tutoring others, not doing all the work for them.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1
    Thanks for all the help:
    Here's what i've done
    Code:
    {
    s1();d1();c=0;
    while(a!='\r')
    	{
    	a=getch();
    	if(a==77)    /*ASCII code for right arrow*/
    		c++;
    	if(a==75)   /*ASCII code for left arrow*/
    		c--;
    	if(c>3||c<-3)
    		{c=0;}
    	if(c==1||c==-3)
    		{mc=2;s2();d2();}
    	if(c==2||c==-2)
    		{mc=3;s3();d3();}
    	if(c==3||c==-1)
    		{mc=4;s4();d4();}
    	if(c==0)
    		{mc=1;s1();d1();}
    	}
    if(mc==1)
    	{pro1();}
    if(mc==2)
    	{pro2();}
    if(mc==3)
    	{pro3();}
    if(mc==4)
    	{pro4();}
    
    /*s1,s2,s3,s4 are functions that uses cprintf to display the selected menu */
    Thanks again for all the help
    Last edited by ghofigjong; 12-02-2002 at 04:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  3. Mystery bug in simple program? - I am beginner
    By archie123 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2005, 07:23 AM
  4. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM