LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-27-2004, 03:28 AM   #1
Bean101
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware 9.1
Posts: 7

Rep: Reputation: 0
Integer To a String in C


h is an int; number in the 5000's.

char *ret;

got a for loop running

this is where h is being set. i need to add -h to the end of ret.
so ret will look something like this when the loop is done
5000-5001-5002 but a string.
 
Old 05-27-2004, 03:45 AM   #2
duncanbojangles
Member
 
Registered: Jul 2003
Posts: 34

Rep: Reputation: 15
You're looking for itoa();
This is a good little tutorial on itoa() and some others you might be interested in: http://www.iota-six.co.uk/c/g3_atoi_...ntf_sscanf.asp
Hope this helps.
 
Old 05-27-2004, 04:46 AM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
sprintf() will also do what you need.
Code:
void foo(char *ret){
        int h=0;
        char tmp[6]={0x00};
        *ret=0x00;
        for(h=5000;h<5004;h++){
               sprintf(tmp,"%d-",h);
               strcat(ret,tmp);
        }
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ string to integer conversion fatman Programming 6 06-18-2006 08:17 AM
C how to convert an integer to string? totti10 Programming 10 11-10-2005 05:49 AM
How do you convert a string to an integer? wbdune Linux - Newbie 11 11-01-2003 02:01 PM
C programming assigning an integer value to a string Linh Programming 4 06-22-2003 07:02 AM
convert integer to string (atoi?) lea Programming 6 10-11-2002 05:16 PM


All times are GMT -5. The time now is 07:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration