Click to See Complete Forum and Search --> : ASCII Characters
How do i display the ASCII code for a character?
parksie
Sep 9th, 2000, 04:13 PM
Try:
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.
For some reason when i use (int) it returns
-6
every time.
parksie
Sep 10th, 2000, 05:23 AM
That's funny - it works on mine :(.
Mine outputs:
101
108
108
111
32
87
111
114
108
100
0
HarryW
Sep 11th, 2000, 07:49 AM
What happened to your 'H', parksie?
parksie
Sep 11th, 2000, 01:43 PM
Unnkkgghhh...
Sorry - I wasn't thinking straight:
char *pcMyString = "Hello World";
char *p = pcMyString;
while(*p) {
cout << *p << " : " << (int)(*p) << endl;
p++;
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.