Solved

itoa() function

Posted on 2001-07-10
7
30,692 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:nhphu
7 Comments
 
LVL 4

Expert Comment

by:newmang
Comment Utility
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
 

Expert Comment

by:sunsrigod
Comment Utility
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
 
LVL 5

Expert Comment

by:garboua
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 4

Expert Comment

by:newmang
Comment Utility
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
 
LVL 2

Accepted Solution

by:
obg earned 10 total points
Comment Utility
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
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
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
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
Zero response, finalized
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now