• C

Simple library Q

What function in what library do I need to convert an integer to a string
Who is Participating?
Answers2000Connect With a Mentor Commented:
_itoa (not all compilers have this - some omit underscore) or sprintf

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

int main( int argc, char * argv[] )
char s1[256] ;
char s2[256] ;
int i1 = 1 ;
int i2 = 2 ;

sprintf( s1, "%d", i1 ) ;
_itoa i2, s2, 10 ) ; /* 10 = base ten */

return 0 ;


oops typo, I meant:
_itoa( i2, s2, 10 ) ; /* 10 = base ten */
martincollisAuthor Commented:
I am compiling in gcc (on unix), and the _itoa seems to be accepted except the demonstration code returns a segmentation fault when executed.
Any ideas?
martincollisAuthor Commented:
By the way I am removing the sprintf line!
You'd be more portable keeping the sprintf and removing the _itoa line
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.