Thread: Problem with atoi and itoa

  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
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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, 02:06 PM
  2. Atoi & Itoa
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 06-17-2002, 06:01 AM