• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Simple library Q

What function in what library do I need to convert an integer to a string
0
martincollis
Asked:
martincollis
  • 2
  • 2
1 Solution
 
Answers2000Commented:
_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 ;

}



0
 
Answers2000Commented:
oops typo, I meant:
_itoa( i2, s2, 10 ) ; /* 10 = base ten */
0
 
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?
0
 
martincollisAuthor Commented:
By the way I am removing the sprintf line!
0
 
ozoCommented:
You'd be more portable keeping the sprintf and removing the _itoa line
0
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.

Join & Write a Comment

Featured Post

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now