468,484 Members | 1,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

integer to char*

I got an integer what I trying to use with allegro function
textout_ex() but it wants an char[]/char* as arg... And I really don't
know how to cast it to one...
Jan 15 '08 #1
3 3212
ro*********@gmail.com wrote:
I got an integer what I trying to use with allegro function
textout_ex() but it wants an char[]/char* as arg... And I really don't
know how to cast it to one...
Why feed an int to a function requiring a char*? Do you really want to
pass an integer, or have you confused a character representing a number
with the number itself?

For example, int a = 7 and char a = '7' are very different objects.
There is a difference between the number seven and the character '7'.

I suggest you do not cast an integer to a char*; instead use the integer
to create a char* that is the character representing that number. Look
up ASCII on wikipedia and you'll see the standard numerical
representations for each standard ASCII character. You'll soon see the
link between a number and the numerical code that indicates the
character representing that number in the ASCII character set.

'Chops

Jan 15 '08 #2
ro*********@gmail.com wrote:
I got an integer what I trying to use with allegro function
textout_ex() but it wants an char[]/char* as arg... And I really don't
know how to cast it to one...
Uh... The only "cast" I can think of is the 'lexical_cast' from 'Boost'
library. Otherwise, you probably want to convert the integer into its
external representation. See 'sprintf' or 'std::ostringstream', etc.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 15 '08 #3
On 15 Jan, 19:29, moschops <mosc...@madasafish.comwrote:
rob.ahlb...@gmail.com wrote:
I got an integer what I trying to use with allegro function
textout_ex() but it wants an char[]/char* as arg... And I really don't
know how to cast it to one...

Why feed an int to a function requiring a char*? Do you really want to
pass an integer, or have you confused a character representing a number
with the number itself?

For example, int a = 7 and char a = '7' are very different objects.
There is a difference between the number seven and the character '7'.

I suggest you do not cast an integer to a char*; instead use the integer
to create a char* that is the character representing that number. Look
up ASCII on wikipedia and you'll see the standard numerical
representations for each standard ASCII character. You'll soon see the
link between a number and the numerical code that indicates the
character representing that number in the ASCII character set.

'Chops
Based on the name of the function, I think the OP just needs
an integer-to-string conversion.
Two steps:
1. See http://www.parashift.com/c++-faq-lit....html#faq-39.1
to see how to convert an int to a std::string (the FAQ is for doubles,
but
you can adapt it easily to int, and I see no need for the exception
stuff
in that case).
2. textout_ex(std_string_from_step_1.c_str());

Jan 15 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by David Fisher | last post: by
27 posts views Thread by Daniel Lidström | last post: by
5 posts views Thread by Vtd | last post: by
8 posts views Thread by El Camino | last post: by
21 posts views Thread by Frederick Gotham | last post: by
130 posts views Thread by euler70 | last post: by
30 posts views Thread by =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.