![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 592
Rep Power: 5
![]() |
How would I convert an integer to a string? I tried using itoa but I read its not included in the Linux libraries :wacko:
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
sprintf() is what you're looking for.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int x = 322;
char c[4];
sprintf(c, "%d", x);
printf("%s", c);
return 0;
}
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 5
![]() |
>sprintf() is what you're looking for.
Though sprintf is a prime suspect for buffer overflow. libc supports snprintf, and the advantage of safety outweighs the disadvantage of being non-portable (though C99 does support it). |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|