public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* convert number to string
@ 2003-12-18 18:09 Tom Tran
  2003-12-18 18:14 ` Segher Boessenkool
  2003-12-18 18:24 ` Tom Tran
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Tran @ 2003-12-18 18:09 UTC (permalink / raw)
  To: gcc-help

I am trying to convert a number to a string. The C book I have states
that the function is in stdlib.h, For example, the syntax for itoa() is:

        char *itoa(int value, char *string, int radix)

Here is my convtst.c:

#include <stdio.h>
#include <stdlib.h>
main()
{
   char *s[17];
   int x = 1234;
   itoa(x, s, 10);
   printf("%s\n", s);
   return 0;
 }
I compiled the program as:    gcc convtst.c -oconvtst
gcc gave error: undefined reference to atoi

Is there a function to convert float to string, s.a. ftoa()?, in stdlib

Please help.  Thanks.
Tom Tran

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: convert number to string
  2003-12-18 18:09 convert number to string Tom Tran
@ 2003-12-18 18:14 ` Segher Boessenkool
  2003-12-19  5:17   ` Kartik Raghavan
  2003-12-18 18:24 ` Tom Tran
  1 sibling, 1 reply; 4+ messages in thread
From: Segher Boessenkool @ 2003-12-18 18:14 UTC (permalink / raw)
  To: Tom Tran; +Cc: gcc-help

> I am trying to convert a number to a string. The C book I have states
> that the function is in stdlib.h, For example, the syntax for itoa() 
> is:

Have a look at sprintf() (or better, snprintf()).


Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: convert number to string
  2003-12-18 18:09 convert number to string Tom Tran
  2003-12-18 18:14 ` Segher Boessenkool
@ 2003-12-18 18:24 ` Tom Tran
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Tran @ 2003-12-18 18:24 UTC (permalink / raw)
  To: gcc-help

Please disregard the question. I can use sprintf() to convert number to
string.

Thank you.
Tom Tran

Tom Tran wrote:

> I am trying to convert a number to a string. The C book I have states
> that the function is in stdlib.h, For example, the syntax for itoa() is:
>
>         char *itoa(int value, char *string, int radix)
>
> Here is my convtst.c:
>
> #include <stdio.h>
> #include <stdlib.h>
> main()
> {
>    char *s[17];
>    int x = 1234;
>    itoa(x, s, 10);
>    printf("%s\n", s);
>    return 0;
>  }
> I compiled the program as:    gcc convtst.c -oconvtst
> gcc gave error: undefined reference to atoi
>
> Is there a function to convert float to string, s.a. ftoa()?, in stdlib
>
> Please help.  Thanks.
> Tom Tran

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: convert number to string
  2003-12-18 18:14 ` Segher Boessenkool
@ 2003-12-19  5:17   ` Kartik Raghavan
  0 siblings, 0 replies; 4+ messages in thread
From: Kartik Raghavan @ 2003-12-19  5:17 UTC (permalink / raw)
  To: Segher Boessenkool, Tom Tran; +Cc: gcc-help


----- Original Message ----- 
From: "Segher Boessenkool" <segher@kernel.crashing.org>
To: "Tom Tran" <tom.tran@noaa.gov>
Cc: <gcc-help@gcc.gnu.org>
Sent: Thursday, December 18, 2003 11:44 PM
Subject: Re: convert number to string


> > I am trying to convert a number to a string. The C book I have states
> > that the function is in stdlib.h, For example, the syntax for itoa() 
> > is:
> 
> Have a look at sprintf() (or better, snprintf()).
> 
> 
> Segher
> 
> 

You can try strtoul() or strtol().

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-12-19  5:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-18 18:09 convert number to string Tom Tran
2003-12-18 18:14 ` Segher Boessenkool
2003-12-19  5:17   ` Kartik Raghavan
2003-12-18 18:24 ` Tom Tran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).