Is there a better way of doing this ?

This is a discussion on Is there a better way of doing this ? within the C++ Programming forums, part of the General Programming Boards category; I am getting the input (left arrow or right arrow) using the following code: PHP Code: int grabinput () {      ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    5

    Is there a better way of doing this ?

    I am getting the input (left arrow or right arrow)
    using the following code:
    PHP Code:
    int grabinput()
    {
        
    char c;
        
    getch();
        
        if ((float) 
    == 27)
        {
            return 
    2;
        }
        else if ((float) 
    == 75)
        {
            return 
    0;
        }
        else if ((float) 
    == 77)
        {
            return 
    1;
        }
        
        
    fflush(stdin);
        return -
    1;

    (returns 2 for escape, 0 for left, 1 for right - keys ... and -1 just in case something else happens)

    Is there a better/standard way of doing this ? If so, how ?

    www.akilla.tk

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    Code:
    int grabinput(){
    
          char c;
          c = getch();
    
          switch((int)c){
                 case 27:
                          return 2;
                 case 75:
                          return 0;
                 //ect
                 default:
                          return -1;      
          }
    }
    Why don't you just put your logic inside of the case statements as oppose to implementing it based on return values?
    Last edited by Traveller; 07-21-2002 at 11:24 AM.

Popular pages Recent additions subscribe to a feed

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