itoa() in Linux

  • Follow


Hi all, I'm using the itoa function in my C code but it does not
compile in Linux 2.4 (Redhat). I have stdilb.h included. I thought itoa
is part of the standard C library, but on doing a "man itoa" it tells
me no such man entry exists. But I could find atoi as part of the
library. Does that mean I need to implement the itoa function? Is there
any other way?

Thank you.

0
Reply pinaki_m77 (96) 10/28/2005 8:39:38 PM

googler wrote:
> Hi all, I'm using the itoa function in my C code but it does not
> compile in Linux 2.4 (Redhat). I have stdilb.h included. I thought itoa
> is part of the standard C library, but on doing a "man itoa" it tells
> me no such man entry exists. But I could find atoi as part of the
> library. Does that mean I need to implement the itoa function? Is there
> any other way?
> 
> Thank you.
> 

Try the following:

char number[32];

snprintf(number, 32, "%d", integer_value);

--

Fletcher Glenn

0
Reply Fletcher 10/28/2005 8:51:10 PM


itoa() is not part of the C standard library.  You need to include
extension.h.

0
Reply David 10/29/2005 3:12:51 AM

"David Shin" <David.W.Shin@gmail.com> writes:
> itoa() is not part of the C standard library.  You need to include
> extension.h.

There is no extension.h header on any Linux system I'm aware of.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.
0
Reply Keith 10/30/2005 10:37:12 AM

"googler" <pinaki_m77@yahoo.com> schreef in bericht 
news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
> Hi all, I'm using the itoa function in my C code but it does not
> compile in Linux 2.4 (Redhat). I have stdilb.h included. I thought itoa
> is part of the standard C library, but on doing a "man itoa" it tells
> me no such man entry exists. But I could find atoi as part of the
> library. Does that mean I need to implement the itoa function? Is there
> any other way?
>
> Thank you.
>

use stringstream instead

string MyClass::Int2Asc(int intval)
{
    stringstream s
    s << intval;
    return s.str();
}

John




0
Reply Bruintje 10/30/2005 5:03:03 PM

"Bruintje Beer" <me@knoware.nl> said:
>"googler" <pinaki_m77@yahoo.com> schreef in bericht 
>news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
>> Hi all, I'm using the itoa function in my C code but it does not
>> compile in Linux 2.4 (Redhat). I have stdilb.h included.
>
>use stringstream instead
>
>string MyClass::Int2Asc(int intval)
....

Note; the original article discussed C code, not C++. The two languages
are different.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
0
Reply Juha 10/30/2005 5:31:42 PM

"Juha Laiho" <Juha.Laiho@iki.fi> schreef in bericht 
news:dk301u$ur8$1@ichaos.ichaos-int...
> "Bruintje Beer" <me@knoware.nl> said:
>>"googler" <pinaki_m77@yahoo.com> schreef in bericht
>>news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
>>> Hi all, I'm using the itoa function in my C code but it does not
>>> compile in Linux 2.4 (Redhat). I have stdilb.h included.
>>
>>use stringstream instead
>>
>>string MyClass::Int2Asc(int intval)
> ...
>
> Note; the original article discussed C code, not C++. The two languages
> are different.
> -- 
> Wolf  a.k.a.  Juha Laiho     Espoo, Finland
> (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
>         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
> "...cancel my subscription to the resurrection!" (Jim Morrison)

you can use c++ compiler to compile c programs and have the advantage of c++ 
string classes

john 


0
Reply Bruintje 11/5/2005 7:19:29 AM

"Bruintje Beer" <me@knoware.nl> wrote:
>
>you can use c++ compiler to compile c programs and have the advantage of c++
>string classes

C and C++ are two distinctly different languages, which have a
common subset.  If you compile it with a C++ compiler, it isn't
C.

-- 
FloydL. Davidson           http://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska)                      floyd@apaflo.com
0
Reply Floyd 11/5/2005 9:24:35 AM

"Bruintje Beer" <me@knoware.nl> said:
>"Juha Laiho" <Juha.Laiho@iki.fi> schreef in bericht 
>news:dk301u$ur8$1@ichaos.ichaos-int...
>> "Bruintje Beer" <me@knoware.nl> said:
>>>"googler" <pinaki_m77@yahoo.com> schreef in bericht
>>>news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
>>>> Hi all, I'm using the itoa function in my C code but it does not
>>>> compile in Linux 2.4 (Redhat). I have stdilb.h included.
>>>
>>>use stringstream instead
>>>
>>>string MyClass::Int2Asc(int intval)
>> ...
>>
>> Note; the original article discussed C code, not C++. The two languages
>> are different.
>
>you can use c++ compiler to compile c programs and have the advantage of c++ 
>string classes

... at which point the code is no longer C (you can't compile it with a C
compiler). There is a case where a completely valid ANSI C program doesn't
go through a C++ compiler:

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char **argv) {
        printf("%d\n",10//*foo*/2);
        exit(0);
}

-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
0
Reply Juha 11/6/2005 8:54:30 AM

Juha Laiho <Juha.Laiho@iki.fi> writes:

>"Bruintje Beer" <me@knoware.nl> said:
>>"Juha Laiho" <Juha.Laiho@iki.fi> schreef in bericht 
>>news:dk301u$ur8$1@ichaos.ichaos-int...
>>> "Bruintje Beer" <me@knoware.nl> said:
>>>>"googler" <pinaki_m77@yahoo.com> schreef in bericht
>>>>news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
>>>>> Hi all, I'm using the itoa function in my C code but it does not
>>>>> compile in Linux 2.4 (Redhat). I have stdilb.h included.
>>>>
>>>>use stringstream instead
>>>>
>>>>string MyClass::Int2Asc(int intval)
>>> ...
>>>
>>> Note; the original article discussed C code, not C++. The two languages
>>> are different.
>>
>>you can use c++ compiler to compile c programs and have the advantage of c++ 
>>string classes

>.. at which point the code is no longer C (you can't compile it with a C
>compiler). There is a case where a completely valid ANSI C program doesn't
>go through a C++ compiler:

>#include <stdio.h>
>#include <stdlib.h>

>int
>main(int argc, char **argv) {
>        printf("%d\n",10//*foo*/2);
>        exit(0);
>}


Is this still valid C99?

Casper
-- 
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
0
Reply Casper 11/6/2005 9:37:38 AM

M�ns Rullg�rd wrote:
> Casper H.S. Dik <Casper.Dik@Sun.COM> writes:
> 
> 
>>Juha Laiho <Juha.Laiho@iki.fi> writes:
>>
>>
>>>"Bruintje Beer" <me@knoware.nl> said:
>>>
>>>>"Juha Laiho" <Juha.Laiho@iki.fi> schreef in bericht 
>>>>news:dk301u$ur8$1@ichaos.ichaos-int...
>>>>
>>>>>"Bruintje Beer" <me@knoware.nl> said:
>>>>>
>>>>>>"googler" <pinaki_m77@yahoo.com> schreef in bericht
>>>>>>news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
>>>>>>
>>>>>>>Hi all, I'm using the itoa function in my C code but it does not
>>>>>>>compile in Linux 2.4 (Redhat). I have stdilb.h included.
>>>>>>
>>>>>>use stringstream instead
>>>>>>
>>>>>>string MyClass::Int2Asc(int intval)
>>>>>
>>>>>...
>>>>>
>>>>>Note; the original article discussed C code, not C++. The two languages
>>>>>are different.
>>>>
>>>>you can use c++ compiler to compile c programs and have the
>>>>advantage of c++ string classes
>>
>>>.. at which point the code is no longer C (you can't compile it with a C
>>>compiler). There is a case where a completely valid ANSI C program doesn't
>>>go through a C++ compiler:
>>
>>>#include <stdio.h>
>>>#include <stdlib.h>
>>
>>>int
>>>main(int argc, char **argv) {
>>>       printf("%d\n",10//*foo*/2);
>>>       exit(0);
>>>}
>>
>>Is this still valid C99?
> 
> 
> This is valid C99, but not C++:
> 
> int
> main(int argc, char **argv)
> {
>     int class = 17;
>     return 0;
> }
> 
There's more subtle differences as well.

struct foo {
	int a;
	int b;
};

int
main(int argc, char **argv)
{
	int foo = 42;
	printf("%u\n",(unsigned)sizeof(foo));
	return 0;
}

0
Reply ISO 11/6/2005 2:55:21 PM

Casper H.S. Dik <Casper.Dik@Sun.COM> writes:

> Juha Laiho <Juha.Laiho@iki.fi> writes:
>
>>"Bruintje Beer" <me@knoware.nl> said:
>>>"Juha Laiho" <Juha.Laiho@iki.fi> schreef in bericht 
>>>news:dk301u$ur8$1@ichaos.ichaos-int...
>>>> "Bruintje Beer" <me@knoware.nl> said:
>>>>>"googler" <pinaki_m77@yahoo.com> schreef in bericht
>>>>>news:1130531978.715232.34760@g49g2000cwa.googlegroups.com...
>>>>>> Hi all, I'm using the itoa function in my C code but it does not
>>>>>> compile in Linux 2.4 (Redhat). I have stdilb.h included.
>>>>>
>>>>>use stringstream instead
>>>>>
>>>>>string MyClass::Int2Asc(int intval)
>>>> ...
>>>>
>>>> Note; the original article discussed C code, not C++. The two languages
>>>> are different.
>>>
>>>you can use c++ compiler to compile c programs and have the
>>>advantage of c++ string classes
>
>>.. at which point the code is no longer C (you can't compile it with a C
>>compiler). There is a case where a completely valid ANSI C program doesn't
>>go through a C++ compiler:
>
>>#include <stdio.h>
>>#include <stdlib.h>
>
>>int
>>main(int argc, char **argv) {
>>        printf("%d\n",10//*foo*/2);
>>        exit(0);
>>}
>
> Is this still valid C99?

This is valid C99, but not C++:

int
main(int argc, char **argv)
{
    int class = 17;
    return 0;
}

-- 
M�ns Rullg�rd
mru@inprovide.com
0
Reply iso 11/6/2005 3:06:38 PM

"Nils O. Sel�sdal" <noselasd@asgaard.homelinux.org> writes:

> M�ns Rullg�rd wrote:
>> Casper H.S. Dik <Casper.Dik@Sun.COM> writes:
>>
>>>>.. at which point the code is no longer C (you can't compile it with a C
>>>>compiler). There is a case where a completely valid ANSI C program doesn't
>>>>go through a C++ compiler:
>>>
>>>>#include <stdio.h>
>>>>#include <stdlib.h>
>>>
>>>>int
>>>>main(int argc, char **argv) {
>>>>       printf("%d\n",10//*foo*/2);
>>>>       exit(0);
>>>>}
>>>
>>>Is this still valid C99?
>> This is valid C99, but not C++:
>> int
>> main(int argc, char **argv)
>> {
>>     int class = 17;
>>     return 0;
>> }
>>
> There's more subtle differences as well.
>
> struct foo {
> 	int a;
> 	int b;
> };
>
> int
> main(int argc, char **argv)
> {
> 	int foo = 42;
> 	printf("%u\n",(unsigned)sizeof(foo));
> 	return 0;
> }
>

That prints 4 in both cases.

-- 
M�ns Rullg�rd
mru@inprovide.com
0
Reply iso 11/6/2005 4:16:02 PM

M�ns Rullg�rd wrote:

>>There's more subtle differences as well.
>>
>>struct foo {
>>	int a;
>>	int b;
>>};
>>
>>int
>>main(int argc, char **argv)
>>{
>>	int foo = 42;
>>	printf("%u\n",(unsigned)sizeof(foo));
>>	return 0;
>>}
>>
> 
> 
> That prints 4 in both cases.
> 

Silly me, make that

#include <stdio.h>

int foo = 42;
int
main(int argc, char **argv)
{
         struct foo { int a; int b; };
         printf("%u\n",(unsigned)sizeof(foo));
         return 0;
}
0
Reply ISO 11/7/2005 2:54:39 PM

"Nils O. Sel�sdal" <noselasd@asgaard.homelinux.org> writes:

> M�ns Rullg�rd wrote:
>
>>>There's more subtle differences as well.
>>>
>>>struct foo {
>>>	int a;
>>>	int b;
>>>};
>>>
>>>int
>>>main(int argc, char **argv)
>>>{
>>>	int foo = 42;
>>>	printf("%u\n",(unsigned)sizeof(foo));
>>>	return 0;
>>>}
>>>
>> That prints 4 in both cases.
>>
>
> Silly me, make that
>
> #include <stdio.h>
>
> int foo = 42;
> int
> main(int argc, char **argv)
> {
>          struct foo { int a; int b; };
>          printf("%u\n",(unsigned)sizeof(foo));
>          return 0;
> }

Yep, that prints 4 as C, 8 as C++, just as expected.  Isn't this proof
enough that C++ is evil?

-- 
M�ns Rullg�rd
mru@inprovide.com
0
Reply iso 11/7/2005 6:43:00 PM

14 Replies
1756 Views

(page loaded in 0.159 seconds)

Similiar Articles:

















7/22/2012 12:20:33 AM


Reply: