...

View Full Version : ascii [in c]



chrismiceli
01-02-2003, 03:10 AM
a while ago on the javascript board someone asked how to find out the ascii code of a letter, a response gave him the anser and a nice little page that when a key was pressed it would alert the ascii code, well i just started to learn c about a week ago, and i figured out how to do it.


#include <stdio.h>

void main() {
char key;
printf("press any key:");
key=getchar();
printf("the key was %c\n",key);
printf("the ascii code is %i\n",key);
}

this was tested on redhat 8.0 using the gcc compiler, and it worked great. BTW if you want to find out the ascii code of like the arrow key (->) hit it and then hit enter, it should work.
p.s. if you use dos and windows, chang getchar() to getch(); and add #include <conio.h>

Borgtex
01-02-2003, 10:58 AM
Hummm that's not a javascript, so maybe this post should go to Computer Programming to avoid confusions

jkd
01-02-2003, 07:10 PM
Originally posted by Borgtex
Hummm that's not a javascript, so maybe this post should go to Computer Programming to avoid confusions

True. :)

chrismiceli
01-03-2003, 12:07 AM
sorry :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum