I want the user to use the four cursors up,down,right,left.
i tried to use getch() but it didnt work because the four have the same ASCII code which is 224, so i cant diffrentiate between them
plz any one tell me how to make the user use them
aam and another thing
i want what i display on the screen to be bold
like DANI WEB How can i do it
plz reply me
thnx

Try something like this:

#include <stdio.h> 
#include <conio.h> 

/* System dependent key codes */
enum
{
  KEY_ESC     = 27,
  ARROW_UP    = 256 + 72,
  ARROW_DOWN  = 256 + 80,
  ARROW_LEFT  = 256 + 75,
  ARROW_RIGHT = 256 + 77
};

static int get_code ( void )
{
  int ch = getch();

  if ( ch == 0 || ch == 224 )
    ch = 256 + getch();

  return ch;
}

int main ( void )
{
  int ch;

  while ( ( ch = get_code() ) != KEY_ESC ) {
    switch ( ch ) {
    case ARROW_UP:
      printf ( "UP\n" );
      break;
    case ARROW_DOWN:
      printf ( "DOWN\n" );
      break;
    case ARROW_LEFT:
      printf ( "LEFT\n" );
      break;
    case ARROW_RIGHT:
      printf ( "RIGHT\n" );
      break;
    }
  }

  return 0;
}

Hey, I used to know that arrow keys(left, right, up and down) return ASCII 0 with getch(), then u have to use getch() again to get the value which is like 72, 80 etc.
My experience was limited to DOS, i would like to know which system u were working on that returned 224 first time. In my very first introductory CS class i asked my lecturer why does the arrow keys(and some others) return 0. I know the reason why it is not possible to return an ASCII value but why "0"? Then he barked at me before the whole class, "NOW WHY ARE U ASKING THIS KIND OF QUESTIONS, HOW AM I SUPPOSED KNOW THAT? U GO ASK THE PERSON WHO MADE THIS COMPUTER".

Can any one plz enlighten me with this piece of knowledge?

>i would like to know which system u were working on that returned 224 first time.
The good news is that by the mention of getch (and no mention of curses) you can assume either Windows or DOS. So if it's not DOS proper, it must be a Windows version. ;) Booting into Windows and testing the first return of getch confirms this assumption.

>HOW AM I SUPPOSED KNOW THAT?
Silly teacher. He could have at least guessed that it was an arbitrary extension code that was conveniently a not often used value. :rolleyes:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.