Problem with atoi and itoa

This is a discussion on Problem with atoi and itoa within the C Programming forums, part of the General Programming Boards category; Code: itoa(atoi(SUM)*=i,SUM,10); That wont work because atoi(SUM) will not multiply by i for some reason. How do i fix this. ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    6

    Problem with atoi and itoa

    Code:
    itoa(atoi(SUM)*=i,SUM,10);
    That wont work because atoi(SUM) will not multiply by i for some reason. How do i fix this. Also the value of atoi(SUM) is too big to be held as an integer of any type which is why i am using a char array for SUM.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
    atoi(SUM)*=i
    The *= operator assigns a new value to the left operand - and you shouldn't be assigning a value to a function's return value. Just use straight multiplication and you should be fine.

    I'm confused by the rest of your problem. A char is just one byte, but an integer is 4, depending on your implementation. How are you getting a char to hold more? Do you mean you're using a string to represent that number in Base-36 or something?

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Also, remember that although atoi() is a standard function, itoa() is NOT. Use strtol() instead.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Doesn't strtol() just do what atoi() does? ltostr isn't standard either...

    There's plenty of source code out there to code up your own function if you want to...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 01:06 PM
  2. Atoi & Itoa
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 06-17-2002, 06:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21