itoa() function

Hi All,
I'm using a simple program to test itoa() function in Red Hat 6.2. The program as follow:
////////test.c/////////////////
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
    char buffer[20];
    int base;
    for( base = 2; base <= 16; base += 2 ) {
        printf( "%2d %s\n", base,
            itoa( 12765, buffer, base ) );
    }
    return EXIT_SUCCESS;
}
///////////////////////////////////
and then i compile:
 gcc -o test.out test.c
but there is errorr:
  /tmp/cci2KXGm.o: In function `main':
  /tmp/cci2KXGm.o(.text+0x2c): undefined reference to `itoa'
  collect2: ld returned 1 exit status
I use gcc 2.95.2, libc-2.1.3.so

Please help me.
Thank
nhphuAsked:
Who is Participating?
 
obgCommented:
There is no itoa. Here are a couple of functions that you can look up in the man pages (to see if they exist on your system).

   char *ltostr(long n, int base);
   char *ultostr(unsigned long n, int base);
   char *ltoa(long n);
   char *ultoa(unsigned long n);
0
 
newmangCommented:
I may be getting old and forgetful (According to my kids I am) but I can't recall an itoa function. atoi, atol etc I do use but not itoa. The gcc compiler on linux and cc compiler on Solaris don't have any reference to these functions either.

You can achieve the required result for base 8, 10 & 16 using the sprintf function but for the others you'll probably have to do it manually by repeated divisions by the base number.

Cheers - Gavin
0
 
sunsrigodCommented:
hi,

  u don't have a built-in library function for itoa in gcc in redhat Linux. so u will surely get this undefined reference to itoa error.
  if u want to get rid od this error then u have to write a function called itoain the same program.
  if u want a itoa converter program i can send it to u or just apply the logic given by Mr.Gavin to get the result.
 
regards,
 Sri
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
garbouaCommented:
I do believe that newmang is OLD, because I'm old and i don't recall itoa(), at any Rate, sprintf will work, or you can visit the code farm at www.sourceforge.com and pick a converter, many available.
0
 
newmangCommented:
garboua

newmang admits that he is OLD (I started working on computers with real core memories not these new fangled silicon memories we have these days and I well remember coding on paper tapes and punched cards).

But my memory remains intact - there hasn't been an itoa function but they are a snip to code anyway.

Cheers from the old folks home - gavin
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE KnowledgePro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20010050.html
http://www.experts-exchange.com/questions/Q.20107628.html
http://www.experts-exchange.com/questions/Q.20149667.html
http://www.experts-exchange.com/questions/Q.20149670.html
http://www.experts-exchange.com/questions/Q.20150228.html
http://www.experts-exchange.com/questions/Q.20148893.html
http://www.experts-exchange.com/questions/Q.20242817.html
http://www.experts-exchange.com/questions/Q.20248210.html
http://www.experts-exchange.com/questions/Q.20247071.html




**** PLEASE DO NOT AWARD THE POINTS TO ME. *****
 
------------>  EXPERTS:  Please leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
MoondancerCommented:
Zero response, finalized
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.

All Courses

From novice to tech pro — start learning today.