473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3539
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: David Fisher | last post by:
The most common sizes of integer types seem to be: 8 bits - signed char 16 bits - short 16 or 32 bits - int 32 or 64 bits - long Question #1: Does anyone know how common sizes other than...
27
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just...
5
by: Vtd | last post by:
Hi All, Simple question regarding byte to integer conversion: integers are 32, char is 8 bits. unsigned int a; int b; char c; .... a = (unsigned int)c; /* c is 0 extended to integer (upper...
8
by: El Camino | last post by:
I need to switch a string to an integer if its strLetter = "A" integer value of 1 if its strLetter = "B" then integer value of 2 if its strLetter = "C" then integer value of 3
21
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me....
1
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a...
20
by: Wabz | last post by:
Hello mates, Does anyone know how to write a function that tests if an integer is a palindrome in C language?
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is useful for representing the values of individual...
30
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Let's say we had a simple function for returning the amount of days in a month: unsigned DaysInMonth(unsigned const month) { switch (month) { case 8: case 3: case 5:
9
by: tsuyois | last post by:
Hi, I just signed in to this excellent network. I hope I could get some answers to many questions I have in writing C compilers. My first question is: Is "integer demotion" required in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.