Selection menu with "Enter" key support

This is a discussion on Selection menu with "Enter" key support within the C Programming forums, part of the General Programming Boards category; Hello, I am working on a database project, which can store (initially) 10,000 marksheets with following capabilities 1) new entry ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Question Selection menu with "Enter" key support

    Hello,
    I am working on a database project, which can store (initially) 10,000 marksheets with following capabilities
    1) new entry
    2) edit/modification of entry
    3)delete entry
    4) separate Departements ( BBA, BCS, M.Phil, Phd., etc.)
    5) can store data on files ( initially, all data is stored in a single file)

    now, i want to create a menu, in which i can use arrow keys to navigate through the menu and use Enter key fo selection.

    can any body give any idea about, what should i use in it??

    P.S: The project is only on C language.

    Thanks.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Depending on your OS, you need a library like curses to handle the arrow keys.

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    welll thanks for suggession, i made a 4 function calculator by using this theme,
    but the problem is
    1) the menu is at the corner and i want it to be in center or whrere i want.
    2) the program is not correctly working in "abc.exe" file. it is showing ANSI codes.

    plz tell me how to upload code here so you can chek it.

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    Code:
    /*menu.c*/
    #include<stdio.h>
    #include<conio.h>
    #include<graphics.h>
    #define TRUE 1
    #define NUM 5
    #define CLEAR "\x1B[2J"
    #define ERASE "\x1B[K"
    #define NORMAL "\x1B[0m"
    #define REVERSE "\x1B[7m"
    #define HOME "\x1B[1;1f"
    #define BOTTOM "\x1B[20;1f"
    #define U_ARRO 72
    #define D_ARRO 80
    #define INSERT 82
    void action(int);
    char getcode(void);
    void display (char *arr[], int size, int pos);
    void add (void);
    void sub (void);
    void mul (void);
    void div (void);
    int mana (void);
    void main (void)
    {
        printf("***************  calculator ***************");
        mana();
        printf("***************************** THE END ***********************");
    }
    
    
    int mana (void)
    {
    
    
        static char *items[NUM] =
            { "add",
              "sub",
              "mul",
              "div",
              "quit", };
        int curpos;
        printf(CLEAR);
        curpos=0;
    
    
        while(TRUE)
            {
            display(items,NUM,curpos);
            switch (getcode() )
                {
                case U_ARRO:
                    if( curpos>0) --curpos; break;
                case D_ARRO:
                    if( curpos< NUM-1) ++curpos; break;
                case '\r':
                    action(curpos); break;
                }
    }        }
    
    
    
    
    /*display() */
    /* displays menu*/
    void display(char *arr[], int size, int pos)
    {
        int j;
        clrscr();
        printf(HOME);
        for(j=0; j<size; j++)
    
    
            {
            if(j==pos)
    
    
            printf(REVERSE);
            printf("%s \n", *(arr+j) );
            printf(NORMAL);
    
    
            }
        printf(BOTTOM);
    }
    
    
    /*get code*/
    /* gets keyboard code*/
    
    
    char getcode(void)
    {
        int key;
    
    
        if( (key=getch()) ==0)
            return(getch() );
        else if ( key== '\r')
            return(key);
        else
            return(0);
    }
    /*action() */
    /* perform action based on cursor position */
    
    
    void action(int pos)
    {
    
    
        printf(ERASE);
        switch(pos)
            {
            case 0:
                add(); break;
            case 1:
                sub(); break;
            case 2:
                mul(); break;
            case 3:
                div(); break;
            case 4:
                exit(0);
            }
    }
    
    
    void add (void)
    {
    int x,y,z;
    clrscr();
    printf(" \n enter number one=");
    scanf("%d",&x);
    printf(" \n enter number two=");
    scanf("%d",&y);
    z=x+y;
    printf("\n \n \n %d",z);
    getch();
    }
    
    
    void sub (void)
    {
    int x,y,z;
    clrscr();
    printf(" \n enter number one=");
    scanf("%d",&x);
    printf(" \n enter number two=");
    scanf("%d",&y);
    z=x-y;
    printf("\n \n \n %d",z);
    getch();
    }
    
    
    void mul (void)
    {
    int x,y,z;
    clrscr();
    printf(" \n enter number one=");
    scanf("%d",&x);
    printf(" \n enter number two=");
    scanf("%d",&y);
    z=(x*y);
    printf("\n\n");
    printf("\n\n %d",z);
    getch();
    }
    
    
    void div (void)
    {
    float x,y,z;
    clrscr();
    printf(" \n enter number one=");
    scanf("%f",&x);
    printf(" \n enter number two=");
    scanf("%f",&y);
    z=(x/y);
    printf("\n\n");
    printf("\n\n %4f",z);
    getch();
    }

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You operating system is Windows, right?

    Your compiler is Turbo C, right?

    Do you HAVE to use Turbo C for this, or can you update to a MUCH better IDE/compiler, that is free?

    The reason I ask is Turbo C is a 16 bit program that won't run in Windows 7, natively. Also, it's very limited in the size of programs you can create, array sizes you can construct, etc.

    May I suggest using either Microsoft's free C ide/compiler, Pelles C ide/compiler or Codeblocks IDE with Ming for Windows compiler? (I use Pelles C, and love it!).
    Last edited by Adak; 04-28-2013 at 02:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with Nested "Switch Multiple-Selection"
    By MAV_DevWantB in forum C Programming
    Replies: 5
    Last Post: 09-18-2009, 08:05 AM
  2. Replies: 8
    Last Post: 08-23-2009, 01:33 PM
  3. Why some linux shell doesn't support "Delete" Key?
    By meili100 in forum Tech Board
    Replies: 18
    Last Post: 09-30-2008, 07:09 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21