Reputation: 23
I have a program that generates/'rolls' two dice. I would like to output these two values to a MessageBox, for example: "Dice Rolled: 1 and 3".
The problem I am having is how to go about concatenating these integers to the string. The code I have so far is as follows:
MessageBox( NULL, // hWnd - window owner (none)
L"Dice:", // lpText - text for message box
L"Dice rolled:", // lpCaption - title for message box
MB_OK | // uType - make ok box
MB_ICONEXCLAMATION);
What would be the best way to go about doing this?
Thanks in advance.
Upvotes: 0
Views: 633
Reputation: 100748
The problem is that C really doesn't support strings as a data type, so you will need to simulate strings using character arrays. For example:
int die1, die2; /* need to be set somehow */
wchar_t dice[100];
wsprintf(dice, L"Dice: %d and %d", die1, die2);
MessageBox(NULL, dice, L"Dice Rolled:", MB_OK | MB_ICONEXCLAMATION);
Upvotes: 2
Reputation: 10546
You should use sprintf to create a string:
sprintf(s, "Dice rolled: %d and %d", dice1, dice2)
Upvotes: 0