This topic is now archived and is closed to further replies.

How Do You Add Strings And Numbers To Display Them On A MessageBox?

This topic is 5043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Oh yay! Finally a question a newbie like me can answer! (hopefully...)

I'd convert the numbers to strings and then add the strings together through some weird function (in c++ anyhow, which i'm assuming is what you have)

void addToString(char* ,char );

// ...

int main() {

char pretext[] = "x equals ";
int number = 5;
char textnum = number + 48; // Now the integer 5 is converted

// to string 5

char posttext[] = ", and thats just dandy";
addToStr(pretext, textnum); // Function modifies pretext[] by adding textnum to it

addToStr(pretext, posttext);

// Now pretext contains (hopefully) "x equals 5, and thats just dandy"

// ...

return 0;

void addToString(char* prestr, char poststr)
int index = strlen(prestr) + 1;
for( int i = 0; i < strlen(poststr) + 1; i++)
prestr[index] = poststr[i];

That code will (hopefully) modify pretext so in the end it has the string "x equals 5, and thats just dandy"

BTW you are using c++ are you not?

...and I think you have to #include something to use strlen... I dunno


[edited by - v0dKA on February 20, 2004 6:59:16 PM]

Share this post

Link to post
Share on other sites
Original post by Drastick
char Buffer[1028];
int x = 5;
sprintf(Buffer,"x equals %d, and that''s just dandy", x);
MessageBox( NULL, Buffer, "Message", MB_OK );

should do the trick

Isn''t there a header file needed to use sprintf()?

Share this post

Link to post
Share on other sites