Solved

Simple library Q

Posted on 1998-11-09
5
169 Views
Last Modified: 2010-04-15
What function in what library do I need to convert an integer to a string
0
Comment
Question by:martincollis
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 20 total points
ID: 1254118
_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
 
LVL 8

Expert Comment

by:Answers2000
ID: 1254119
oops typo, I meant:
_itoa( i2, s2, 10 ) ; /* 10 = base ten */
0
 

Author Comment

by:martincollis
ID: 1254120
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
 

Author Comment

by:martincollis
ID: 1254121
By the way I am removing the sprintf line!
0
 
LVL 84

Expert Comment

by:ozo
ID: 1254122
You'd be more portable keeping the sprintf and removing the _itoa line
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question