Solved

Simple library Q

Posted on 1998-11-09
5
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

752 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