Thread: itoa

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    itoa

    I'm having a little trouble with itoa(). Can some one please show me a little example of how to use it.
    What I'm trying to do is make a 6 character string based on the time. Here is what I have:

    Code:
    #include <dos.h>
    
    main()
    {
    struct time t;
    char name[2];
    int result;
    gettime(&t);
    result=itoa(t.ti_hour,name,0);
    printf("%s",result);
    }
    I know I must be calling itoa function wrong but I'm not really sure how. Also can anyone explain the radix value to me? Or at least what value it should be.

    Thanks alot,

    Thantos

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    the radix arguement specifies the base of the number such as the string out will be binary(base 2), octal(base 8), decimal(base 10), hexidecimal(base 16) or up to whatever base 36 is.

    so your call should look like so

    Code:
    #include <dos.h>
    
    main()
    {
        struct time t;
        char name[2]; // this needs to be large enough to hold the int you are gonna convert
    // while 2 will hold the hour 9 would hold anything.
        char* result; // Note this is a char* not an int
        gettime(&t);
        result=itoa(t.ti_hour,name,0);
        printf("%s",result); // or printf("%s",name);
    }
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks for the help. Worked like a charm.

    Thantos

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem using itoa
    By g_p in forum C Programming
    Replies: 2
    Last Post: 05-03-2008, 06:38 AM
  2. Problem with itoa() perhaps?
    By TheSquid in forum C++ Programming
    Replies: 5
    Last Post: 05-08-2006, 02:04 AM
  3. Really Weird itoa Problem
    By Grantyt3 in forum C++ Programming
    Replies: 8
    Last Post: 12-20-2005, 12:44 AM
  4. itoa undeclared?
    By curlious in forum C++ Programming
    Replies: 16
    Last Post: 12-11-2004, 05:30 PM
  5. itoa
    By coldcoyote in forum Linux Programming
    Replies: 4
    Last Post: 02-13-2003, 09:28 AM