Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

itoa() function

Posted on 2001-07-10
7
Medium Priority
?
31,049 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
[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
7 Comments
 
LVL 4

Expert Comment

by:newmang
ID: 6275650
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
ID: 6280509
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
ID: 6287432
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
Independent Software Vendors: 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!

 
LVL 4

Expert Comment

by:newmang
ID: 6287886
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 40 total points
ID: 6298276
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
ID: 6929917
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
ID: 7109128
Zero response, finalized
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

730 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