Thread: Is there a better way of doing this ?

  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