Jump to content
  • Advertisement

Archived

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

Krak

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

This topic is 5295 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

Advertisement
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];
index++;
}
return;
}


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

------------------------------------------------------------
.:<<-v0d[KA]->>:.

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
quote:
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
yep. go with sprintf. it makes your life much easier.

i'm not sure about the header, but i think it's either stdio.h or stdlib.h

[edited by - PmanC on February 20, 2004 7:14:29 PM]

Share this post


Link to post
Share on other sites
Yeah, I daresay that sprintf, and even itoa/strcat would be considerably easier than writing it yourself... Most often things like that have been written before, since they''re so useful and general.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!