DIGIT-ARC read-only archive · snapshot: July 23, 2026

ASCII Code confusion

27 posts · originally from https://geek.digit.in/community/threads/ascii-code-confusion.46289/

n2casey
n2casey Original post #1
Jan 13, 2007 at 1:34 PM
I m working on a project in C++. The prob I m facing is to distinguish between ASCII Codes, since some ASCII codes have two keys for them.

Code:
[b]ASCII Code[/b]     [b]Key-1[/b]     [b]Key-2[/b]

  59            ;         F1
  60            <         F2
  .             =          .
  .             >          .
  .             ?          .
  .             @          .
  .             A          .
  .             B          .
  .             C          .
  68            D         F10

  71            Home      G
  82            Insert    R
                                        etc.

So how to a write program which scan any key but can distinguish between them.
wizrulz
wizrulz #2
Jan 13, 2007 at 3:08 PM
REFER THIS..mi8 help u

*www.ascii.cl/
n2casey
n2casey #3
Jan 13, 2007 at 3:32 PM
wizrulz said:
REFER THIS..mi8 help u

*www.ascii.cl/

I already know about that link but don't get nething there.
ahref
ahref #4
Jan 13, 2007 at 5:25 PM
For key-2, you have to press ctrl key means programatically you have to enable control key, which you can do by modifying memory address 0x417.
n2casey
n2casey #5
Jan 13, 2007 at 6:11 PM
ahref said:
For key-2, you have to press ctrl key means programatically you have to enable control key, which you can do by modifying memory address 0x417.

Plz tell more clearly.
ahref
ahref #6
Jan 13, 2007 at 8:10 PM
check this program
void main()
{
char x,y,z;
clrscr();
printf("Press any key");
x=getch();

if(x==0)
{
y=getch();
printf("\nExtended Ascii code is %d",y);
}
else
{
printf("\nAscii Code is %d",x);
}
getch();
}
n2casey
n2casey #7
Jan 14, 2007 at 11:31 PM
Still facing the problem.

Look at this

Code:
void main()
{
...
char x;
x=getch();
if(x==59)
pf("x = %d",x);
else
pf("\a");
...
....
}

Since according to this table
Code:
[b]ASCII Code[/b]     [b]Key-1[/b]     [b]Key-2[/b]

  59            ;         F1
  60            <         F2
  .             =          .
  .             >          .
  .             ?          .
  .             @          .
  .             A          .
  .             B          .
  .             C          .
  68            D         F10

  71            Home      G
  82            Insert    R
                                        etc.

both ; & F1 key has ASCII code 59 & according to my program I want that when I press F1, a beep sound must b there & x = 59 must not print on screen but when I press ; no beep must occur & x = 59 must print on screen.
That's why I asked to distinguish btwn keys.
ahref
ahref #8
Jan 15, 2007 at 1:00 AM
void main()
{
char x,y,z;
clrscr();
printf("Press any key");
x=getch();

if(x==0)
{
y=getch();
printf("\a");
printf("\nExtended Ascii code is %d",y);
}
else
{
printf("\nAscii Code is %d",x);
}
getch();
}
n2casey
n2casey #9
Jan 15, 2007 at 2:54 PM
ahref said:
void main()
{
char x,y,z;
clrscr();
printf("Press any key");
x=getch();

if(x==0)
{
y=getch();
printf("\a");
printf("\nExtended Ascii code is %d",y);
}
else
{
printf("\nAscii Code is %d",x);
}
getch();
}

I have tried that but still problem not solved coz the statement
Code:
if(x==0)
{
y=getch();
printf("\a");
printf("\nExtended Ascii code is %d",y);
}
never gets executed. Every time I press F1, F2 etc. then first statement is executed & it prints Ascii Code is ...
ahref
ahref #10
Jan 15, 2007 at 4:31 PM
That code should execute when you press F1,F2 key etc. It is working fine in my end. Probably you have to flush your keyboard buffer.
n2casey
n2casey #11
Jan 15, 2007 at 6:33 PM
OK ahref. Unfortunately your trick doesn't work on my system but I have solved my prob by modifying the program code.
Anyway, thx a lot for ur help. Ur trick added a new idea in my programming knowledge.
n2casey
n2casey #12
Jan 26, 2007 at 2:23 AM
Now a new prob. in another program.
Take a look at this prog.

Code:
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
int i=0;
char c='\0',s[50];
clrscr();
do
{
 c=getch();
 if(c>31 && c<127)
 {
  s[i]=c;
  i++;
  }
 else if(c==13)
 printf("%s",s);
 else              //or else if(c==0) both r ineffective
 {
  sound(400);
  delay(50);
  nosound();
  }
 }while(c!=13);
getch();
}

So for this prog, Keys F1 to F12, Home, End etc. must not b stored in string but they r stored in string.
I want that F1, F2.... etc. keys must not b stored in string. How can I do that?
ahref
ahref #13
Jan 26, 2007 at 7:34 AM
I have done slight modifications. now it is not storing function keys check it
Code:
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
int i=0;
char c='\0',s[50],d;
clrscr();
do
{
 c=getch();
 if(c>31 && c<127)
 {
  s[i]=c;
  i++;
  }
 else if(c==13)
 {
 s[i]='\0';
 printf("%s",s);
 }
 else              //or else if(c==0) both r ineffective
 {
  d=getch();
  sound(400);
  delay(50);
  nosound();
  }
 }while(c!=13);
getch();
}
n2casey
n2casey #14
Jan 26, 2007 at 12:43 PM
OK ahref. Thx a lot for ur help.
Ur slight modification made a big difference. I don't know that why that idea doesn't came in my mind :(
Anyway, thx again & repu for u.
Pathik
Pathik #15
Jan 26, 2007 at 12:57 PM
offtopic: wich book to refer for c++... i ll start in a few days...
n2casey
n2casey #16
Jan 26, 2007 at 1:08 PM
pathiks said:
offtopic: wich book to refer for c++... i ll start in a few days...
Book for C++ & OOP in C++, which I have -

THE WAITE GROUP'S
OBJECT ORIENTED PROGRAMMING IN
TURBO C++​
Writer - ROBERT LAFORE
Publishers - Galgotia Publicators Pvt. Ltd., 5, Ansari Road, Daryaganj, New Delhi

Price - 350 Rs.
Pathik
Pathik #17
Jan 26, 2007 at 2:43 PM
@n2casey r u into engg???? wich yr??? wich book is recommended by univ???
n thx for the name.. i ll try to get it...
Ganeshkumar
Jan 26, 2007 at 5:49 PM
Any descent freee e boook???
n2casey
n2casey #19
Jan 26, 2007 at 5:54 PM
pathiks said:
@n2casey r u into engg???? wich yr??? wich book is recommended by univ???
n thx for the name.. i ll try to get it...

I have completed my Engg. in June-06.
The book I have told U is recommended by Univ. for OOP in C++.
In First yr I read Let Us C or C++ by Yashwant Kanitker to learn C from beginning. In third yr I read the book

THE WAITE GROUP'S
OBJECT ORIENTED PROGRAMMING IN
TURBO C++
Writer - ROBERT LAFORE

& that time I come to know that it covers all topic in detail with very ease & lot of exapmles.
Let Us C/C++ both the books r good for beginners & easy too but will not cover all topics & so I told u to read OOP in Turbo C++ by Robert Lafore.
Pathik
Pathik #20
Jan 29, 2007 at 10:18 PM
@n2casey i saw the book OOPS in C++ by robert lafore...
but it was priced 540 rs... r u sure the price is 350 rs.
n2casey
n2casey #21
Jan 29, 2007 at 11:08 PM
pathiks said:
@n2casey i saw the book OOPS in C++ by robert lafore...
but it was priced 540 rs... r u sure the price is 350 rs.

I have purchased it 2 months before in 350 Rs. from Delhi (not from publisher's shop). I will confirm its price & will tell u.

I was reading from my friend's book for last 2 yrs but now I have my own.
Well I suggest u to get one year old edition coz I don't found more changes in the book in last one year.

This link might help u
tuxfan
tuxfan #22
Jan 30, 2007 at 8:33 PM
I have a header file for all these key-codes. :) You have to just #include and start using it ;)

So insted of 0x1b you can use ESC for escape key.

Have a look at *www.mailnspace.com/download/c.source/ :)
n2casey
n2casey #23
Jan 30, 2007 at 11:15 PM
@ tuxfan

Nice link friend. Repu for u.
tuxfan
tuxfan #24
Jan 31, 2007 at 12:34 PM
n2casey said:
@ tuxfan

Nice link friend. Repu for u.
Thanks :)

BTW, any more reps for writing that C code? Each line of code in the files offerred there is written by me! :)) Just pay little more attention to the functions lib and that sample calendar application where those functions are used. ;)
Pathik
Pathik #25
Jan 31, 2007 at 9:47 PM
@n2casey n others...
i saw the book oops in turbo c++ and also Oops in C++ by the same author- r lafore....... wich is better???
@ tuxfan can u also recommend some good book on c++ wich covers all the advanced topics....
n2casey
n2casey #26
Jan 31, 2007 at 10:03 PM
pathiks said:
@n2casey n others...
i saw the book oops in turbo c++ and also Oops in C++ by the same author- r lafore....... wich is better???
@ tuxfan can u also recommend some good book on c++ wich covers all the advanced topics....

OOP in Turbo C++ is much better than OOP in C++.
Also it will cover many advanced topics. It's a good book for both beginners & advance programmers.

One suggestion for u, use the term OOP (Object Oriented Programming) instead of OOPs.
tuxfan
tuxfan #27
Feb 1, 2007 at 11:00 AM
I really have no idea on books on C++. But I have read Yashwant Kanetkar's Let Us C, Pointers in C, etc. and they were good. There is also a book called Let Us C++ by the same author.

I have also read his columns in newspapers, magazines, etc. and know that he is a knowledgeable person who writes well. Try his book.