Thread: what does it mean?

  1. #1
    Unregistered
    Guest

    what does it mean?

    #include <iostream.h>;
    #include<conio.h&ht;
    int main()
    {
    char c=getch();
    while(c != 27)//27 means escape
    {
    switch(c){
    case 'a':
    cout << "you hit a" << endl;
    break;
    }
    }
    return(0);
    }



    //tell me what each thing means please!

  2. #2
    Unregistered
    Guest
    Getch takes a single character input. That input is stored into a char and compared with c. If it is a c, then the output is displayed. Whats the deal?

    <PS: Don't put semi-colons after #include statements>

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    I made a few changes to the program to get it to work correctly but it will display you hit a when an a is entered. If anything else except an esc (escape) is entered it will do nothing but get the next character from the console. If an escape is entered it exits.

    Code:
    #include <iostream.h>//removed the ;
    #include<conio.h> //removed the ;
    
    int main() //entry point for the program
    {
    	char c = ' ';//initialize c to a space
    	
    	while(c != 27)//27 means escape 
    	{ //while c not equal to an escape repeat the follow intructions
    		c = getch(); //get a character from the console
    		
    		switch(c)// test the value of c
    		{ 
    			case 'a': //if c = a not a and A only a then print
    				cout << "you hit a" << endl;		
    				break; //end of 'a'
    		} 
    	} 
    	
    	return 0;// return 0 to caller 
    }

  4. #4
    Unregistered
    Guest
    If 27 means escape, what is left, right, up and down?

  5. #5
    Unregistered
    Guest
    easier explanation for above: where do you find out?

  6. #6
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    check out scan codes and ascii codes... you can detect arrow [and other special] keypresses using scan codes... there is an interrupt which returns each, i'll find my input routine and give you it here in time... but that's a start until i return...
    hasafraggin shizigishin oppashigger...

  7. #7
    Unregistered
    Guest
    where do you find the scan codes or the ascii codes?

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    a textbook is one place. You could try writing a program too, at least for the ASCII codes.

    for(int i = 0; i < 256; i++)
    cout << " the integer " << i << " = " << (char)i << endl;

  9. #9
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    Code:
      //  scan code, then ASCII code
      unsigned int KF :: k_chk___ (vo)  //  SCAN CODE / ASCII check
      {
        __dpmi_regs io;  // or whatever regs structure it is...
    
        if (kbhit ())
        {
    
    //      while (kbhit ())                    //  keep on getting a character / flush
          {
            io.x.ax = 0x00;
            __dpmi_int (0x16, &io);
          }
    
          if (io.h.al == 13)	//  if carriage return, return a 10 instead
            return ((io.h.ah<<8) | 0x000a);
          else  //  else return normal
            return ((io.h.ah<<8) + io.h.al);	//  SCAN CODE / ASCII
          }
          else
          {
            return (0x0000);
          }
      }
    i realized i had to edit it a lot... [must choose 'save tabs as spaces' in my editor...] hehe... any ?uestions? it returns the scan code in the high order byte, and the ascii in the low order byte of a 16-bit unsigned word... [short]
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed