Jump to content
  • Advertisement
Sign in to follow this  
chadsxe

How do I use extended ASCII inside an array....

This topic is 4413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to figure out how to use extended ascii inside my 2-D array like so...
unsigned char maze[ROWMAX][COLMAX] =
{
{'B','B','B','B','B','B','B','B','B','B','B','B','B','B','B','B'},
{'B','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','B'},
{'B','B','B','B','B','B','B','B','B','B',' ','B','B','B',' ','B'},
{'B','W',' ',' ',' ',' ',' ',' ',' ','B',' ','B',' ','B',' ','B'},
{'B','B','B','B','B','B','B','B',' ','B','B','B',' ','B',' ','B'},
{'B',' ',' ',' ',' ',' ',' ','B',' ',' ',' ',' ',' ','B',' ','B'},
{'B','B','B','B','B','B','B','B',' ','B','B','B','B','B',' ','B'},
{'B',' ',' ',' ','B',' ',' ',' ',' ','B',' ',' ',' ',' ',' ','B'},
{'B',' ',' ',' ',' ',' ',' ',' ','B','B','B','B',' ','B','B','B'},
{'B',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','B'},
{'B','B','B','B','B','B','B','B','B','B','B','B','B','B','B','B'}
};

I would like to input the decmial representaion of the extended ASCII character.

Share this post


Link to post
Share on other sites
Advertisement
You have 3 options:

* use an integer value (e.g. 255, 0xFF or 0377 for character #255)
* use an hexadecimal character literal (e.g. '\xFF' for character #255)
* use an octal character literal (e.g. '\0377' for character #255)


The actual character it maps to graphically depends on the code page you are using.

Share this post


Link to post
Share on other sites
I change my array to an intger and then typecasted it to a char when I went to display it. Does this sound resonable or is there a better way of doing this.

EDIT: this did not work for me...

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
You have 3 options:

* use an integer value (e.g. 255, 0xFF or 0377 for character #255)
* use an hexadecimal character literal (e.g. '\xFF' for character #255)
* use an octal character literal (e.g. '\0377' for character #255)


The actual character it maps to graphically depends on the code page you are using.


Can you explain what you mean by code page?

Share this post


Link to post
Share on other sites
unsigned char array[] = { 255, 0xFF, 0377, '\xFF', '\0337' };

No cast required.

Trying to directly use 'ÿ' in your code would be a Bad Idea™, since its value will depend on the code page the file is saved in: 0xFF if you are using Windows 1252, but 0x98 with IBM 850.

Share this post


Link to post
Share on other sites
Quote:
Original post by chadsxe
Can you explain what you mean by code page?


There is no such thing as "Extended ASCII". ASCI only defines code points 0 to 127. The interpretation of char values 128 to 255 depends on the code page you are using, 0x8C could be î (IBM 434, IBM 850) or Œ (Windows 1252) or even a control code (ISO 8859-1).

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
unsigned char array[] = { 255, 0xFF, 0377, '\xFF', '\0337' };

No cast required.

Trying to directly use 'ÿ' in your code would be a Bad Idea™, since its value will depend on the code page the file is saved in.


Duh...I was doing this '255'. Sorry and thanks for the info.

Share this post


Link to post
Share on other sites
Quote:
Original post by chadsxe
Quote:
Original post by Fruny
unsigned char array[] = { 255, 0xFF, 0377, '\xFF', '\0337' };

No cast required.

Trying to directly use 'ÿ' in your code would be a Bad Idea™, since its value will depend on the code page the file is saved in.


Duh...I was doing this '255'. Sorry and thanks for the info.


Is it just me or should that not even compile? Single quotes (') are for chars... '255' is a char array and should have to be in double quotes ("). I'm confused as to how that didn't throw an error.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheUnbeliever
Is it just me or should that not even compile? Single quotes (') are for chars... '255' is a char array and should have to be in double quotes ("). I'm confused as to how that didn't throw an error.

MSVC would have compiled it but should have given him a warning about constant trunctation. Basically it evaluates to 0x00323535. I don't know if that syntax is a MSVC specific thing or not.

Share this post


Link to post
Share on other sites
They are legal, but the value is implementation-defined. (Most likely, it will be as if it were a base-256 value with the ASCII value used for each digit; but that's not guaranteed.)

Quote:

An ordinary character literal that contains a single c-char has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal has type int and implementation-defined value.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!