Jump to content
  • Advertisement

Archived

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

richardve

Oh no, an error?

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

	char *blablabla;
	sprintf( blablabla, "vari = %i", vari);
	MessageBox( NULL, blablabla, "msg", MB_OK);
   
What's wrong with this code? It doesn't work in win2k! btw. I just looove win2k! --- Richard ---------- Edited by - richardve on 6/21/00 4:48:45 AM

Share this post


Link to post
Share on other sites
Advertisement
I''m no windoze api god, and I don''t have w2k, but
maybe it doesn''t like the NULL in:
MessageBox( NULL, blablabla, "msg", MB_OK);

Try passing a valid window handle instead?



----------
Disco Love For Everyone

Share this post


Link to post
Share on other sites
No no no, you have to allocate memory to your pointer before writing to it. Like this:


char *blablabla;
// Allocate 100 bytes to the string
// You can do this using C++:
blablabla = new char [100];
// OR do this in C:
blablabla = (char *)malloc(100);
// Do your stuff with the string here
sprintf( blablabla, "vari = %i", vari);
MessageBox( NULL, blablabla, "msg", MB_OK);
// Free memory
// In C++:
delete [] blablabla;
// OR in C
free(blablabla);


Either way, make sure you allocate at least as many bytes as you plan to use. Keep in mind that in C/C++, strings are null-terminated, which means that most functions will automatically append a ''\0'' character at the end, so you need one byte extra for each string. And don''t forget to free your memory when you no longer need it, or you''ll have memory leaks...

Hope this helps.

Dormeur

Share this post


Link to post
Share on other sites
Woops, I''m feeling very dumb right now...

I think I was a bit sleepy this morning.
Anyway, thanks you very much for the answer!


--- Richard ----------

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!