Thread: a very small task but seems very hard....

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question a very small task but seems very hard....

    Hi feiends,
    a small task but seems very hard,

    reading a array which contains amount of soem bank account,
    task it to read from char array, change to integer , add new deposit to it
    and save back in the char array back.

    till changing the str to int and adding i have done by usinf atoi function and then simple addition.
    then i applied itoa function, but it is saying undefined reference for itoa,
    then i search about it, many places i found some samml demonstrate it, but it is not working with linux.
    i m using GCC compiler , please keep this in mind.
    and plz dont suggest integer instead of char array, that is requirnment of question.
    what you suggest me to do, write another function, or find and use itoa() function.

    waiting for your replies friends....
    plz hurry i m waiting for your intelligents suggestion and solutions.
    regards
    alok

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    This is a probelm that I faced just a couple days ago.

    I used sprintf to convert back to a string like this

    Code:
    char *number;
    
    int i = 100;
    
    sprintf ( (char *) number, "%i", i );
    Good luck,

    B

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >undefined reference for itoa
    Use the versatile and standard library function sprintf():
    Code:
    #include <stdio.h>
    .
    .
    char array[20];
    
    sprintf(array, "%d", amount);

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by SwarfEye
    This is a probelm that I faced just a couple days ago.

    I used sprintf to convert back to a string like this

    Code:
    char *number;
    
    int i = 100;
    
    sprintf ( (char *) number, "%i", i );
    Good luck,

    B
    Good luck is right, if he listens to you! number doesn't point to anything specific, so you'll be very lucky if your program doesn't crash here.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    thankx

    thankx friends by your help i solved the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small executables in VC++ 8
    By Bleech in forum Windows Programming
    Replies: 3
    Last Post: 06-20-2007, 08:28 AM
  2. Creating small executables
    By cloudy in forum C++ Programming
    Replies: 8
    Last Post: 05-25-2006, 01:17 PM
  3. Replies: 1
    Last Post: 01-19-2006, 02:37 PM
  4. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  5. Strange hard disk
    By GanglyLamb in forum Tech Board
    Replies: 20
    Last Post: 03-01-2003, 04:05 AM