Solved

Simple library Q

Posted on 1998-11-09
5
170 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reading tzdatabase for timezone definitions 5 145
First character of input string truncated with scanf 3 102
how to understand recursion 12 230
Problem to ASCII 1 197
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.

828 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