### Thread: Converting Integer to Char using C++

1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
3
Rep Power
0

#### Converting Integer to Char using C++

Ok, I have found no information on converting an integer to a char or adding the integer to a char array. I have found out many ways to change char to integer.

It seems that either I got the idea of using pointers to do the task is wrong or I'm implementing it wrong. Here is the code:

char *temp[20] = (int *) bid.cash;

Uh, the bid.cash is a structure and the cash is type int.

The purpose of the is that I'm doing a for loop to display text character by character to the screen and I guess I could use math to break the number to its smaller parts. This seems, difficult because I don't like to think hard. Well, I could perhaps get the first value by dividing the value by 100 or 1000 if the case may be. Then for the second value divide by one power of ten less then the one before then divide by 10 or 100 then 10. And so on down the loop.

To much work, for the moment at least. I may just break down and try to implement it to the best of my ability. Which isn't much. Most of the problem comes when it comes to 1000. Since the type is integer then there will never be a decimal point. I could check for loop or the lack of thereof then continue on down.

If you read this far, I could, maybe, solve this problem one way but I would rather just convert the integer to char. I hope that it would take less lines and look cleaner.
2. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
3
Rep Power
0
Oh, wait. Couldn't I use % as remander and extract the value that way?
3. I don't understand what you are trying to do.

Are you trying to take a numeric value and create a character string that expresses that value? Like if an int called number had a value of 42, you would create the string "42"?

sprintf(sString,"%d",number);

Or if you insist on using streams, you could use strstream.

strstream str << number;
4. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
3
Rep Power
0
Thank you