# Turn an __int64 into a string...

## Recommended Posts

Hi guys! Got an easy one for you. Here's what I'm trying to do... StringCbPrintf(ScoreStr, sizeof(ScoreStr), "%i", GStuff->P1_GameScore); Pretty easy. Put the value of "GStuff->P1_GameScore" into the char array "ScoreStr[]". The problem I'm having is this: P1_GameScore is a '__int64', because it can get to be a VERY big number. So when I call the above, not all of the number is put into the character array 'ScoreStr'. How do I get a '__int64' variable into a string (char array)? Thanks in advance for the help! [smile]

##### Share on other sites
I think you need to specify the size prefix in your format string: "%I64i" instead of just "%i". Also, make sure your ScoreStr array is large enough; 20+ characters should be sufficient.

##### Share on other sites
You could also get it into a regular std::string (assuming you're using C++) just by doing:

	__int64 big = 0x1234567890ABCDE;	std::strstream strm;	strm << big << std::ends;	std::string str = strm.str();

##### Share on other sites
"%llu" = long long unsigned int
"%lli" = long long int

this is what i know from gcc, it might be the same in VS03 and newer

##### Share on other sites
Quote:
 Original post by mmelsonYou could also get it into a regular std::string (assuming you're using C++) just by doing:*** Source Snippet Removed ***

Um, how many years ago did you learn C++? It's spelled "stringstream" now, and there's no 'ends' nonsense any more.

OP:

1) Referring to char arrays as "strings" makes the baby Zahlman cry.
2) You do know that 32-bit signed integers range up to 2 billion and change, yes? Just what kind of game are you making o_O

##### Share on other sites
Thanks for the info, guys!

Yeah, __int64 is probably overkill since I only want the score to cap at 999,999,999. But when I used the "%i", I couldn't move that info into a char string (because the %i truncated the score value).

So what AP was mentioning:

"%llu" = long long unsigned int
"%lli" = long long int

that should work? I'm at school so I can't test that at the moment. So I should change:

__int64 GStuff->P1_GameScore;
...
StringCbPrintf(ScoreStr, sizeof(ScoreStr), "%i", GStuff->P1_GameScore);

to this:

long unsigned int GStuff->P1_GameScore;
...
StringCbPrintf(ScoreStr, sizeof(ScoreStr), "%llu", GStuff->P1_GameScore);

Does that look correct? Please let me know and I'll try it out when I get home later today. Thanks again for the help!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627694
• Total Posts
2978673

• 19
• 14
• 12
• 10
• 12