ITOA MACRO!

ITOA MACRO!

Post by sur » Fri, 29 Dec 1995 04:00:00



Hi,

I am used to the itoa function in Watcom C compiler. Looks like there is
no equivalent in gcc in Linux.

Does any one know a shorter way to do 'itoa' 'ltoa' 'ftoa' etc.

Please Help!

Suresh.S

 
 
 

ITOA MACRO!

Post by Jason Mcmull » Mon, 01 Jan 1996 04:00:00


: I am used to the itoa function in Watcom C compiler. Looks like there is
: no equivalent in gcc in Linux.

: Does any one know a shorter way to do 'itoa' 'ltoa' 'ftoa' etc.

  Have you looked at sprintf(3) ???

ie:

char __print_buffer[1024];
#define itoa(num) sprintf(__print_buffer,"%d",num)
#define ltoa(num) sprintf(__print_buffer,"%d",num)
#define ftoa(num) sprintf(__print_buffer,"%f",num)

--
Copyright 1995 Jason McMullan;  all rights reserved;  license for the
Microsoft Network to distribute this text for US $100,000 per copy is
hereby granted;  all other use of this text by the Microsoft Network,
including storing, relaying, or reuse is expressly prohibited; distribution
by the Microsoft Network indicates full acceptance of the licensing terms.
MICKEY# 4729-304-8732

 
 
 

ITOA MACRO!

Post by S. L » Mon, 01 Jan 1996 04:00:00





>: I am used to the itoa function in Watcom C compiler. Looks like there is
>: no equivalent in gcc in Linux.

>: Does any one know a shorter way to do 'itoa' 'ltoa' 'ftoa' etc.

>  Have you looked at sprintf(3) ???

>ie:

>char __print_buffer[1024];
>#define ltoa(num) sprintf(__print_buffer,"%d",num)

Although the above should work on linux, it's a good idea to use %ld here.


Witty .sig under construction.

 
 
 

ITOA MACRO!

Post by Ralf W. Steph » Tue, 02 Jan 1996 04:00:00


Quote:sur writes:
> Does any one know a shorter way to do 'itoa' 'ltoa' 'ftoa' etc.

You didn't ask for C++ but let's just look at it:
-------------------
#include <String.h>
#include <stream.h>

int i;
...
String s = dec(i);
-------------------

ralf
--
PGP: 1024/0xA713ECE9 2047/0xC8E605F5

 
 
 

ITOA MACRO!

Post by Mark Addina » Wed, 03 Jan 1996 04:00:00


: : I am used to the itoa function in Watcom C compiler. Looks like there is
: : no equivalent in gcc in Linux.

: : Does any one know a shorter way to do 'itoa' 'ltoa' 'ftoa' etc.

:   Have you looked at sprintf(3) ???

: ie:

: char __print_buffer[1024];

Why so big?

: #define itoa(num) sprintf(__print_buffer,"%d",num)
: #define ltoa(num) sprintf(__print_buffer,"%d",num)
: #define ftoa(num) sprintf(__print_buffer,"%f",num)

Mark.

: --
: Copyright 1995 Jason McMullan;  all rights reserved;  license for the
: Microsoft Network to distribute this text for US $100,000 per copy is
: hereby granted;  all other use of this text by the Microsoft Network,
: including storing, relaying, or reuse is expressly prohibited; distribution
: by the Microsoft Network indicates full acceptance of the licensing terms.
: MICKEY# 4729-304-8732

 
 
 

ITOA MACRO!

Post by Ken Batem » Thu, 04 Jan 1996 04:00:00


sprintf(buffer, "%d", n)

-Ken

 
 
 

ITOA MACRO!

Post by Ali Rahi » Mon, 08 Jan 1996 04:00:00


Quote:>char __print_buffer[1024];
>#define itoa(num) sprintf(__print_buffer,"%d",num)
>#define ltoa(num) sprintf(__print_buffer,"%d",num)
>#define ftoa(num) sprintf(__print_buffer,"%f",num)

If portability is an issue, you shouldn't rely on the return value
of sprintf. SYSV derivatives return a length instead of the buffer
pointer.

 Ali.

 
 
 

1. Gcc support for tchar and itoa()?

Hello,

We are attempting a port from Win32 to Linux.

Under gcc, it appears that there is no support for the tchar data type, nor
for string functions xtoa(), such as itoa(), as they don't appear in any
header files (though they are exported from various libs).

gcc -v gives me:
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

Does GNU simply not support these, or might I have a have a library or
version problem?  It is my understanding that these are C Standard items.

Thanks,
Tony S.

2. DirecDuo

3. No itoa() in Linux?

4. Routing IPX Packets

5. Where is itoa()

6. thread-safe librpc?

7. atoi\itoa

8. Bernoulli 230 MB

9. itoa() in C for unix >>>

10. itoa - error

11. What happened to itoa()?

12. itoa() & ultoa() ?

13. itoa from DavidK