Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » string literal - character code

Credits go to Andrei Ellman and GullRaDriel for helping out!
This thread is locked; no one can reply to it. rss feed Print
string literal - character code
clovekx
Member #3,479
April 2003
avatar

How to insert a character into the string by the characters numeric code?

this works:

printf("%c",0x81);

but these dont:

printf("\x80");
printf("\200");
printf("%c",'\x80');

What's wrong with them? I'm using mingw.

EDIT: Now I see it works with standard printf, but doesnt with texprintf_ex, because char is signed and the value 0x80 is negative.

Andrei Ellman
Member #3,434
April 2003

Are you trying to print the Euro sign? While it's position in the Windows-1252 encoding is 0x80, it's position in the ISO 8859-15 is 0xA4.

As for Allegro's texprintf_ex(), Allegro uses UTF-8 by default, which means that unless you change the text-encoding format with set_uformat(), you must specify character constants in UTF-8 format.

AE.

--
Don't let the illegitimates turn you into carbon.

GullRaDriel
Member #3,861
September 2003
avatar

Little help:

set_uformat( U_ASCII );

Beaten ... I should take less time speaking of hdd's with HoHo ;-p

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

clovekx
Member #3,479
April 2003
avatar

Thanks. Setting uformat works.

Tobias Dammers
Member #2,604
August 2002
avatar

Always does.
You could also use a text editor that supports UTF-8 (scite for example does), but I that'd be hackish, and generally unreadable on a non-utf8-editor. It is very useful when working with XML, though.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Go to: