Thread: Num to String? (atoi inverse)

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48

    Lightbulb Num to String? (atoi inverse)

    how can I do the inverse of atoi? here's the code

    Code:
    Num = atoi(PartC);  // Convert to Number
    Num += 15;      //add 15
    strcat(String, ToString(Num));
    or something like that

    Code:
    Num = atoi(PartC);  // Convert to Number
    Num += 15;      //add 15
    PartC = ToString(Num);
    strcat(String, PartC);
    thanks!

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    sprintf
    Code:
    char buffer[10];
    int val = 20;
    sprintf(buffer,"%d",val);  /* Now buffer has "20" */
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3

  4. #4
    Registered User
    Join Date
    Jun 2007
    Location
    Rio de Janeiro, Brasil
    Posts
    48
    thanks! work great!

  5. #5
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Location
    Scotland
    Posts
    101
    atoi inverse
    You mean itoa.

    Sorry, my reply seems pretty redundant as sprintf works great for this. itoa() isn't in every stdlib though, just a warning.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM