Convert Int to *Char

This is a discussion on Convert Int to *Char within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I've been having a hard time finding an answer to my solution without writting a new function just ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Convert Int to *Char

    Hello everyone,

    I've been having a hard time finding an answer to my solution without writting a new function just to do this.

    How do I convert an Int to a *Char. For example. If my int varibale is 345, I want to convert it to "345."

    What is the correct way to do this?

    Thanks!

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Cast it

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    7
    Do you mean (char*)intVar ?

    Doesnt this just create a char with the ascii value of what the int var is?

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Check out the faq
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    7
    Got it working, thanks!

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    >> Doesnt this just create a char with the ascii value of what the int var is?
    Yes. Casting it won't work.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    7
    I decided to use string instead of char arrays. Thanks for all the help.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    a char array is a string... you are using a c++string instead of a c string

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Talking

    Yes, I know. Excatly

    Go easy on me, I am just now getting back into programming after a few years, well almost 4 now!

    Thanks for your reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:26 PM
  2. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 04:28 AM

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