Help please: itoa() - implicit declaration of function...

Discussion in 'Computer Science & Culture' started by Weitzel, Feb 3, 2002.

Thread Status:
Not open for further replies.
  1. Weitzel Simon Fraser University Registered Senior Member

    Messages:
    51
    Hi... I know there are better boards for this but I was hoping someone out there would immediately recognize the fix for this. I'm a student and the assignment is due Wednesday so the sooner the better =)

    In C++, I have:

    int score;
    char str[50];

    itoa(score, str, 10);

    I'm trying to convert my integer "score" into a string - I figured itoa was the best way. It worked fine in Visual C++ but now that I'm compiling at school on a Unix machine, it gives me the error:

    implicit declaration of function 'int atoi(...)'

    How do I use atoi "explicitly"??? Thanks!
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. James R Just this guy, you know? Staff Member

    Messages:
    30,644
    I think you need a statement like:

    #include <string.h>

    at the top of your file.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. malisha Registered Senior Member

    Messages:
    64
    hi there Weitzel ,

    itoa is not a standard function, its found in stdlib.h
    so #include<stdlib.h> if itoa still does not work that means that the function is not present in the partiucalr distro of c++ u have, the best other way to do it would be to uses sprintf look at the function prototype on google or sumthing and it should show you how to do it.

    hope that helps.
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Weitzel Simon Fraser University Registered Senior Member

    Messages:
    51
    Malisha,

    I completely agree with your guess that itoa must not be present in the version of stdlib.h at school. I ended up using sprintf instead and it works. Thanks!
     
  8. malisha Registered Senior Member

    Messages:
    64
    hey its cool, no problems.
    If you want some really good help though for other questions you might have go to this website, the people here really know whats happening and they answer quick most of the time as well.

    http://www.linuxnewbie.org
     
Thread Status:
Not open for further replies.

Share This Page