Ascii values of chars ?
Just wondering... How can I get the ascii value of a character with VC++ ?
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
char value = 'A'; // value == 65
char array[] = { "A Sucks" }; // array[0] == 65
??
Edited by - Claus Hansen Ries on July 28, 2000 2:44:36 AM
char array[] = { "A Sucks" }; // array[0] == 65
??
Edited by - Claus Hansen Ries on July 28, 2000 2:44:36 AM
Ries
As a matter of interest \0 will set the value of a certain byte to 0. Can I used any number up to 256 with this, like \65 to make an A?
Chris Brodie
the ''\'' character is the escape character, it stops the following character as being taken literally, for example:
\n - newline
\t - tab
\r - carriage return.
\\ - backslash
\" - Quote
\65 would escape the 6, but not the 5. 6 is not a valid escape character, so you would end up with unpredictable results.
When it comes to characters they''re pretty much the equivilant to a short int. If you want to set a character you can do it in one of three ways:
char value = ''A'';
char value = 65;
char value = (char)65;
And to answer the original question to display the ascii value of a character using printf:
char value = ''A'';
printf("Ascii value: %d",&value); // Prints out 65
printf("Char: %c",&value); // Prints out A
printf is strongly typed so you specify your format.
I think with cout, you would have to cast the char to an int, but I''m not sure of that, something like:
cout << (int)value;
Hope this helps.
\n - newline
\t - tab
\r - carriage return.
\\ - backslash
\" - Quote
\65 would escape the 6, but not the 5. 6 is not a valid escape character, so you would end up with unpredictable results.
When it comes to characters they''re pretty much the equivilant to a short int. If you want to set a character you can do it in one of three ways:
char value = ''A'';
char value = 65;
char value = (char)65;
And to answer the original question to display the ascii value of a character using printf:
char value = ''A'';
printf("Ascii value: %d",&value); // Prints out 65
printf("Char: %c",&value); // Prints out A
printf is strongly typed so you specify your format.
I think with cout, you would have to cast the char to an int, but I''m not sure of that, something like:
cout << (int)value;
Hope this helps.
"We who cut mere stones must always be envisioning cathedrals"
It worked !
Here''s what I did: I wanted to convert a character to it''s ascii value, so all I did is:
char letter;
letter = ''A''; // For example
return(((int)letter)-32)
And everything looks great.
Thanks for the help
The road to success is always under construction
Here''s what I did: I wanted to convert a character to it''s ascii value, so all I did is:
char letter;
letter = ''A''; // For example
return(((int)letter)-32)
And everything looks great.
Thanks for the help
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
That''s because I made a font bitmap (With the Bitmap Font Builder) that made the rows and cols of the font as 16x8 (Bitmap size is 512x512).
So, to get to the right letter I needed to substract 32.
The road to success is always under construction
So, to get to the right letter I needed to substract 32.
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement