ascii

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Tk

ascii

Post by Tk »

I swear, this had better be helpful to someone, i had to enter every single one of these by hand, you wont find these anywhere. The Bloody [] are specifiers, there supposed to be like that. This is a complete ascii chart. I use this in my os as a qwerty keymap. I load the value into _AL and print it. if you use it please tell me, just so i know it was useful.

Code: Select all

char ascii[127];
ascii[0] = ''; /* Null */
ascii[1] = ''; /* SOH */
ascii[2] = ''; /* STX */
ascii[3] = ''; /* ETX */
ascii[4] = ''; /* EOT */
ascii[5] = ''; /* ENQ */
ascii[6] = ''; /* ACK */
ascii[7] = ''; /* BEL */
ascii[8] = ''; /* BS  */ /* Backspace */
ascii[9] = '\t'; /* TAB */ /* Tab */
ascii[10] = '\n'; /* LF */ /* Newline */
ascii[11] = ''; /* VT */ /* Verticle Tab */
ascii[12] = ''; /* FF */ /* NP Form feed, new page */
ascii[13] = '\c\r'; /* CR */ /* Carriage Return - \c\r */
ascii[14] = ''; /* Shift Out */
ascii[15] = ''; /* Shift In */
ascii[16] = ''; /* DLE */ /* Data link escape */
ascii[17] = ''; /* DC1 */ /* Device control 1 */
ascii[18] = ''; /* DC2 */ /* Device control 2 */
ascii[19] = ''; /* DC3 */ /* Device control 3 */
ascii[20] = ''; /* DC4 */ /* Device control 4 */
ascii[21] = ''; /* NAK */ /* Negative acknowledge */
ascii[22] = ''; /* SYN */ /* Synchronous idle */
ascii[23] = ''; /* ETB */ /* End of trans. block */
ascii[24] = ''; /* CAN */ /* Cancel */
ascii[25] = ''; /* EM  */ /* End of medium */
ascii[26] = ''; /* SUB */ /* subsitute */
ascii[27] = ''; /* ESC */ /* Escape */
ascii[28] = ''; /* FS  */ /* File Seperator */
ascii[29] = ''; /* GS  */ /* group seperator */
ascii[30] = ''; /* RS  */ /* Record seperator */
ascii[31] = ''; /* US  */ /* Unit seperator */
ascii[32] = ' '; /* Space */ /* Space */
ascii[33] = '!';
ascii[34] = '"'; 
ascii[35] = '#'; 
ascii[36] = '$';  
ascii[37] = '%';
ascii[38] = '&'; 
ascii[39] = '''; 
ascii[40] = '('; 
ascii[41] = ')'; 
ascii[42] = '*'; 
ascii[43] = '+'; 
ascii[44] = ','; 
ascii[45] = '-'; 
ascii[46] = '.'; 
ascii[47] = '/'; 
ascii[48] = '0'; 
ascii[49] = '1'; 
ascii[50] = '2'; 
ascii[51] = '3'; 
ascii[52] = '4'; 
ascii[53] = '5'; 
ascii[54] = '6'; 
ascii[55] = '7'; 
ascii[56] = '8'; 
ascii[57] = '9'; 
ascii[58] = ':'; 
ascii[59] = ';'; 
ascii[60] = '<'; 
ascii[61] = '='; 
ascii[62] = '>';
ascii[63] = '?'; 
ascii[64] = '@'; 
ascii[65] = 'A'; 
ascii[66] = 'B'; 
ascii[67] = 'C'; 
ascii[68] = 'D'; 
ascii[69] = 'E'; 
ascii[70] = 'F'; 
ascii[71] = 'G'; 
ascii[72] = 'H'; 
ascii[73] = 'I'; 
ascii[74] = 'J'; 
ascii[75] = 'K'; 
ascii[76] = 'L'; 
ascii[77] = 'M'; 
ascii[78] = 'N'; 
ascii[79] = 'O'; 
ascii[80] = 'P';
ascii[81] = 'Q'; 
ascii[82] = 'R'; 
ascii[83] = 'S';
ascii[84] = 'T';
ascii[85] = 'U';
ascii[86] = 'V';
ascii[87] = 'W';
ascii[88] = 'X';
ascii[89] = 'Y';
ascii[90] = 'Z';
ascii[91] = '[';
ascii[92] = '\';
ascii[93] = ']';
ascii[94] = '^';
ascii[95] = '_';
ascii[96] = '`';
ascii[97] = 'a';
ascii[98] = 'b';
ascii[99] = 'c';
ascii[100] = 'd';
ascii[101] = 'e';
ascii[102] = 'f';
ascii[103] = 'g';
ascii[104] = 'h';
ascii[105] = 'i';
ascii[106] = 'j';
ascii[107] = 'k';
ascii[108] = 'l';
ascii[109] = 'm';
ascii[110] = 'n';
ascii[111] = 'o';
ascii[112] = 'p';
ascii[113] = 'q';
ascii[114] = 'r';
ascii[115] = 's';
ascii[116] = 't';
ascii[117] = 'u';
ascii[118] = 'v';
ascii[119] = 'w';
ascii[120] = 'x';
ascii[121] = 'y';
ascii[122] = 'z';
ascii[123] = '{';
ascii[124] = '|';
ascii[125] = '}';
ascii[126] = '~';
ascii[127] = ''; /* DEL */ /* Delete */
paulbarker

Re:ascii

Post by paulbarker »

I have the same with #defines kicking around. Any unprintable characters should be done as '\nn' where nn is the number rather than the character.

This table can be abbreviated to:

Code: Select all

ascii[n] = n;
EDIT: actually, the difference from above is you have '\c\r' for a carriage return. How do 2 chars fit in a single char?
proxy

Re:ascii

Post by proxy »

TK,

I'm sorry to say that this table is fairly useless :( since you could just cast an int to a char, since '0' when treated as an int is...48 and likewise for all other characters.

Also as the other poster noted, you put 2 chars into a single char, which is an error, i doubt it would compile with all warnings enabled and strict ansi mode.

One thing i dont understand is why you say you use it as a qwerty keymap...are you claiming to use it to convert scancodes to letters (if so, this table is wrong)? If not, then perhaps I misunderstood what you were trying to say.

proxy
Tk

Re:ascii

Post by Tk »

Yep your right, the table is completly screwed. I made a quick app in realbasic to print out the first "ascii[N] = ' + ';"
And of course this is flawed, becuase of the ''' , '\' , ect. And no, you are able to use \c\r in turbo c without error, as it becomes a constant define automaticly.

return
proxy

Re:ascii

Post by proxy »

And no, you are able to use \c\r in turbo c without error, as it becomes a constant define automaticly.
well first of all, just because some compiler lets you do it, doesn't make it legal remember this.

secondly the statement that it becomes a define automatically doesn't make much sense because you are still trying to store a value in a place that it doesn't fit.

what you are doing is is effectivly:

char x = 0x0a0d;

which after looking at it again, is _legal_ but still incorrect, it will automatically be truncated down to 0x0a, and any compiler worth using will give you a warning about it.

gcc gives me the following warnings on this code:

Code: Select all


#include <stdio.h>
int main() {
   char x = '\c\r';
   printf("%d\n", x);
   return 0;
}
test.c:5:11: warning: unknown escape sequence '\c'
test.c:5:11: warning: multi-character character constant
test.c: In function `main':
test.c:5: warning: overflow in implicit constant conversion
and of course this program prints 13.

also if you re-write it to the numeric values of the chars like i said it is equivalent to you get this:

Code: Select all

#include <stdio.h>

int main() {
   char x = 0x0a0d;
   printf("%d\n", x);
}
test.c: In function `main':
test.c:5: warning: overflow in implicit constant conversion
and once again prints 13

proxy
Kemp

Re:ascii

Post by Kemp »

You do know that the entire table is basically useless anyway as you are effectively storing the value 48 at location 48, the value 49 at location 49, etc. If you ever needed to look a printable character up then you'd just get back the same value you were using as your index.

eg

Code: Select all

printf("%c", ascii[48]);
is effectively the same as

Code: Select all

printf("%c", 48);
Much better just to do some basic checks for non-printable characters rather than bloat your code with the entire table.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:ascii

Post by Solar »

Tk wrote:...you wont find these anywhere.
Just to frustrate you completely, try www.asciitable.com. ;D

Sorry, but you've just been bitten by rookie-ness. 8)

Not too bad, though. At least you (thought you) solved a problem, created code, and published it. I started my long road to geekdom by asking really stupid questions. ;)

I have to second my forespeakers, though. '\c' I've never seen so far, "\r\n" is Windows-specific, and '\r\n' is bogus code. '' is bogus, too. '' might be what appears on your screen, but that isn't the correct representation either. Code 12 (vertical tab) is '\v' (at least in C99), and in the end, just cast your array index to (char) and you get the same result.

But then again, at least you didn't fall for the "all the world is US ASCII" trap and only defined the first 127 characters - there is hope. 8)

(Get me right. I'm not making fun of you. It's just kind of cute to see someone who reminds me so much of myself when I started with this stuff... makes you feel wise and very, very old at the same time. ;) )
Every good solution is obvious once you've found it.
mystran

Re:ascii

Post by mystran »

Also on at least Linux, one can type "man ascii" to get a list of ascii characters and numerical codes in octal, decimal and hex..
Ryu

Re:ascii

Post by Ryu »

In windows you can get the heximals values with Character Map, but does not display those non drawn characters like CF, LF hmm so I guess my information is next to useless.
Post Reply