|
-
Sep 9th, 2000, 03:46 PM
#1
How do i display the ASCII code for a character?
-
Sep 9th, 2000, 04:13 PM
#2
Monday Morning Lunatic
Try:
Code:
char *pcMyString = "Hello World";
char *p = pcMyString;
while(*(p++)) {
cout << (int)(*p) << endl;
}
If you cast a char to an int, it works fine. Note that it displays a 0 as the last character.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 9th, 2000, 04:48 PM
#3
For some reason when i use (int) it returns
-6
every time.
-
Sep 10th, 2000, 05:23 AM
#4
Monday Morning Lunatic
That's funny - it works on mine .
Mine outputs:
Code:
101
108
108
111
32
87
111
114
108
100
0
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 11th, 2000, 07:49 AM
#5
Frenzied Member
What happened to your 'H', parksie?
Harry.
"From one thing, know ten thousand things."
-
Sep 11th, 2000, 01:43 PM
#6
Monday Morning Lunatic
<twitches>
Unnkkgghhh...
Sorry - I wasn't thinking straight:
Code:
char *pcMyString = "Hello World";
char *p = pcMyString;
while(*p) {
cout << *p << " : " << (int)(*p) << endl;
p++;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|