returning the ascii character code of a single character
i''m working on a drawfont class, but i need the index of the ascii character code. like is there a function where you would pass "a" and it would return lowercase a''s ascii code?
int __toascii( int c );
Return Value
__toascii converts a copy of c if possible, and returns the result.
Parameter
c = Character to convert
Remarks
The __toascii routine converts the given character to an ASCII character.
Return Value
__toascii converts a copy of c if possible, and returns the result.
Parameter
c = Character to convert
Remarks
The __toascii routine converts the given character to an ASCII character.
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
What language?
If you''re using c/c++ then if you interperate the "a" as a char type you have the ASCII code there already. If you''re using a char* as your string. (say a variable called "text" nice obvious name, thats a char* (i.e. string)) containing the text "hello world". Then
Hope this helps (if you''re using c/c++)
NightWraith
If you''re using c/c++ then if you interperate the "a" as a char type you have the ASCII code there already. If you''re using a char* as your string. (say a variable called "text" nice obvious name, thats a char* (i.e. string)) containing the text "hello world". Then
text[1]
would return the char ''e'' (or in actually fact the ASCII code for ''e'', 101.Hope this helps (if you''re using c/c++)
NightWraith
NightWraith
billybob - you could also write your own little function in your program.
int asciicode(char c)
{
return c;
}
would work fine and return the ascii code everytime for the character you wanted.
int asciicode(char c)
{
return c;
}
would work fine and return the ascii code everytime for the character you wanted.
That wouldn''t be how __toascii works SteveBe.
Ascii codes are 7-bit, so you would want to return c & 0x7f.
Also c is an int, not a char.
Characters above 0x7f in "ascii" tables are non-standard.
char __toascii(int c)
{
if ( ( c & 0x7f ) == c ) return c;
else return 0;
}
Ascii codes are 7-bit, so you would want to return c & 0x7f.
Also c is an int, not a char.
Characters above 0x7f in "ascii" tables are non-standard.
char __toascii(int c)
{
if ( ( c & 0x7f ) == c ) return c;
else return 0;
}
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement