Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opposite of atoi()???

251 views
Skip to first unread message

Tim McGuire

unread,
Mar 11, 1998, 3:00:00 AM3/11/98
to

I know that atoi(char*) will change a string into an integer, but how do I
change an integer into a string???

-Tim McGuire
tmcg...@superior.net, ICQ 5757950
http://www.superior.net/~tmcguire/

firewind

unread,
Mar 11, 1998, 3:00:00 AM3/11/98
to

On Wed, 11 Mar 1998, Tim McGuire wrote:

> I know that atoi(char*) will change a string into an integer, but how do I
> change an integer into a string???

You should read the FAQ before posting to -any- newsgroup, including this
one. Why don't you go do that now.

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.
-- John Winters <jo...@polo.demon.co.uk> in comp.lang.c


SweetPrnze

unread,
Mar 12, 1998, 3:00:00 AM3/12/98
to

sprintf( ... ) will do the trick for you.

Rick

>Subject: Opposite of atoi()???
>From: Tim McGuire <tmcg...@superior.net>
>Date: Wed, Mar 11, 1998 21:32 EST
>Message-id: <Pine.NEB.3.96.98031...@nimbus.superior.net>


>
>I know that atoi(char*) will change a string into an integer, but how do I
>change an integer into a string???
>

Bob Nelson

unread,
Mar 12, 1998, 3:00:00 AM3/12/98
to

Tim McGuire <tmcg...@superior.net> wrote:
> I know that atoi(char*) will change a string into an integer, but how
> do I change an integer into a string???

As you doubtlessly saw in the C-FAQ-list, the sprintf function will
do this. Presumably you were just checking to make sure that the
answer in 13.1 is still correct after your last reading of that august
document. I can assure you that its wise counsel is still valid.

--
========================================================================
Bob Nelson -- Dallas, Texas, USA (bne...@iname.com)
Well...Unix, of course. Because windoze is a pathethic toy...
God bless Texas and the death penalty

Joshua Waxman

unread,
Mar 12, 1998, 3:00:00 AM3/12/98
to

On Wed, 11 Mar 1998, Tim McGuire wrote:

> I know that atoi(char*) will change a string into an integer, but how do I
> change an integer into a string???
>

> -Tim McGuire
> tmcg...@superior.net, ICQ 5757950
> http://www.superior.net/~tmcguire/
>
>
>
>

sprintf (my_string, "%d", my_int);


Stephan Wilms

unread,
Mar 12, 1998, 3:00:00 AM3/12/98
to

Tim McGuire wrote:
>
> I know that atoi(char*) will change a string into an integer, but how do I
> change an integer into a string???

Hi Tim McGuire,

From the comp.lang.c FAQ:
13.1: How can I convert numbers to strings (the opposite of atoi)?
Is there an itoa function?

You can get the FAQ at http://www.eskimo.com/~scs/C-faq/top.html or
at ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/C-FAQ-list and it gets
posted to this newsgroup and to news.answers regularly (at the
beginning of each month).

Stephan
(initiator of the campaign against grumpiness in c.l.c)

Colin Dooley

unread,
Mar 14, 1998, 3:00:00 AM3/14/98
to Tim McGuire

Tim McGuire wrote:
>
> I know that atoi(char*) will change a string into an integer, but how do I
> change an integer into a string???
>

sprintf();


--
<\___/>
/ O O \
\_____/ FTB.

Murray

unread,
Mar 14, 1998, 3:00:00 AM3/14/98
to

Don't be such an ass....maybe he didn't know about the FAQ (?)
Obviously new to C programming.
Give people a break sometimes.

Bob Nelson wrote:

> Tim McGuire <tmcg...@superior.net> wrote:
> > I know that atoi(char*) will change a string into an integer, but how
> > do I change an integer into a string???
>

Lawrence Kirby

unread,
Mar 15, 1998, 3:00:00 AM3/15/98
to

In article <350B37FC...@geocities.com>
pyr...@geocities.com "Murray" writes:

>Don't be such an ass....maybe he didn't know about the FAQ (?)
>Obviously new to C programming.

This isn't about C programming, it is about basic netiquette. You should
check whether any newsgroup has a FAQ before posting to it. See
news.announce.newusers for more information.

--
-----------------------------------------
Lawrence Kirby | fr...@genesis.demon.co.uk
Wilts, England | 7073...@compuserve.com
-----------------------------------------


Sean Mathias

unread,
Mar 16, 1998, 3:00:00 AM3/16/98
to

On 12 Mar 1998 06:17:08 GMT, sweet...@aol.com (SweetPrnze) wrote:
itoa()

>
>sprintf( ... ) will do the trick for you.
>
>Rick
>
>>Subject: Opposite of atoi()???
>>From: Tim McGuire <tmcg...@superior.net>
>>Date: Wed, Mar 11, 1998 21:32 EST
>>Message-id: <Pine.NEB.3.96.98031...@nimbus.superior.net>
>>
>>I know that atoi(char*) will change a string into an integer, but how do I
>>change an integer into a string???
>>

RD Ultra

unread,
Mar 24, 1998, 3:00:00 AM3/24/98
to

>Opposite of atoi()???

Use the sprintf() function. Like printf() it formats numbers
but instead of its output going to the screen it is stored in a
buffer you specify. For example;

char buffer[80];
int x;

sprintf(buffer, "%i", x);


Will Flor

unread,
Mar 24, 1998, 3:00:00 AM3/24/98
to

That will work; there's also an itoa() although I'm not sure if it's in the
standard library.

-Will Flor wi...@will-flor.spamblock.com
Appropriately adjust my return address to reach me via e-mail.

Ryan Younce

unread,
Mar 24, 1998, 3:00:00 AM3/24/98
to

Will Flor <wi...@will-flor.spamblock.com> wrote:
>>sprintf(buffer, "%i", x);

> That will work; there's also an itoa() although I'm not sure if it's in the
> standard library.

It's not. sprintf() seems to be the most common portable solution.

Ryan Younce

firewind

unread,
Mar 24, 1998, 3:00:00 AM3/24/98
to

On Tue, 24 Mar 1998, Will Flor wrote:

> there's also an itoa() although I'm not sure if it's in the standard library.

It isn't.

Chetan C. Narsude

unread,
Mar 27, 1998, 3:00:00 AM3/27/98
to

On Fri, 27 Mar 1998 09:35:22 GMT, L.V.Raghavendra Kumar wrote:
raghav>=>> there's also an itoa() although I'm not sure if it's in the standard
raghav>+>>library.
raghav>=>
raghav>=>It isn't.
raghav>=>
raghav>
raghav>U can use sprintf for the above purpose: to convert integer to a string.
raghav>

Raghav,
U forgot the thank your old pal !!

cheers,
chetan
--
[====================================================================]
Chetan Chandrahas Narsude
Senior, Computer Science and Engineering,
Indian Institute of Technology, Bombay.
Phone: +91-022-5906113
Email: chetan....@usa.net HomePage: www.cse.iitb.ernet.in/~ccn
[====================================================================]

0 new messages