Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Converting from an int to a string in C?
Results 1 to 4 of 4

Thread: Converting from an int to a string in C?

  1. #1
    norfolknchance
    Guest

    Converting from an int to a string in C?

    How do you convert from an int to a string? I found the itoa function and imported the write header files, but it does not compile:

    #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;
    }

    Is there another function that will work?

    Regards,

    Lloyd

  2. #2
    Stuka
    Guest

    Re:Converting from an int to a string in C?

    Check the man page for itoa - I haven't used it recently, but IIRC it does NOT return the result...it actually puts it into the buffer specified. Try moving the itoa() call before the printf, then calling printf with buffer where you have your itoa() call now.

  3. #3
    ediks
    Guest

    Re:Converting from an int to a string in C?

    use sprintf();

    So if I needed 50500 converted into a string, I would do

    {
    char str[5];

    sprintf(str, "%d", 50500);
    }

  4. #4
    ediks
    Guest

    Re:Converting from an int to a string in C?

    here is a good link for all sort of converting

    http://www.iota-six.co.uk/c/28a_atoi.htm

Similar Threads

  1. find a string
    By svar in forum Linux - General Topics
    Replies: 2
    Last Post: 05-01-2009, 08:21 PM
  2. converting quicktime .mov to avi
    By doggiebone in forum Redhat / Fedora
    Replies: 3
    Last Post: 05-19-2003, 01:27 AM
  3. converting gf, special char problems
    By in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 06-03-2002, 07:55 AM
  4. Converting Old PCs into Standalone X Terminals
    By stryder144 in forum General Chat
    Replies: 4
    Last Post: 05-13-2002, 03:40 AM
  5. Converting .raw to .iso :)
    By Feztaa in forum Linux - Software, Applications & Programming
    Replies: 8
    Last Post: 01-24-2002, 10:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •