Jump to content
  • Advertisement
Sign in to follow this  
wioneo

Converting Double to Char Array

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

I thought that simply using the caption for debugging purposes would be easier than drawing on the screen, but then I realized that I cannot do it properly. Whenever I tried(to add a numerical variable to the caption), the caption randomly changed between random bits of rubbish.

So I found this topic...
http://www.gamedev.net/community/forums/topic.asp?topic_id=309934&whichpage=1?

...but the solution that supposedly worked for that person causes an assertion error for me, and the topic is retired, so any pointers regarding this would be greatly appreciated.

I noticed that the 'SDL_WM_SetCaption' function does not accept 'string' type variables which contradicted my belief that 'strings' and 'char' arrays were interchangeable.

Also, does anyone know a way to view variable values while the program is running(not paused at a line) by specifying a scope or something in VS 2010?

EDIT: I think that I found a tutorial on this at...
http://lazyfoo.net/SDL_tutorials/lesson15/index.php
...reading it now....
EDIT:: And now VS is telling me "incomplete type is not allowed" when I type 'std::stringstream cap;' with <string> included.

[Edited by - wioneo on July 20, 2010 12:36:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
sprintf works too!

char Buffer[1024];
double MyVar = 3.1415;
sprintf(Buffer,"%f",MyVar);

//print to stdout (could also do the %f stuff here)
printf(Buffer);

//print to the output window of visual studio
OutputDebugString(Buffer);

//print to a file (could also do the %f stuff here)
fprintf(File,Buffer);

hope that helps!

Share this post


Link to post
Share on other sites
Well thank you that works perfectly.

EDIT: Also, why did you choose to call it "buffer"?
EDIT:: Also is there a referrence list of OpenGL functions divided by category? I'm guessing the answer is no based on how many alphabetic oens I'm seeing, but one of those would be fantastic.

[Edited by - wioneo on July 20, 2010 3:50:30 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by wioneo
EDIT: Also, why did you choose to call it "buffer"?


Buffer (n):
5. Computer Science A device or area used to store data temporarily.

Buffer is a commonly used name for a specific type of temporary variable where the exact name doesn't matter. 'temp' would have worked as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by wioneo
EDIT:: And now VS is telling me "incomplete type is not allowed" when I type 'std::stringstream cap;' with <string> included.
Did you include <sstream>?

Share this post


Link to post
Share on other sites
Quote:
Original post by _fastcall
Quote:
Original post by wioneo
EDIT:: And now VS is telling me "incomplete type is not allowed" when I type 'std::stringstream cap;' with <string> included.
Did you include <sstream>?


I'll assume that was my problem, but It's cleared now. I thought that would cause an undefined error, though.

Share this post


Link to post
Share on other sites
Quote:
I noticed that the 'SDL_WM_SetCaption' function does not accept 'string' type variables which contradicted my belief that 'strings' and 'char' arrays were interchangeable.


A char* can be passed to a function that expects a std::string. This works because std::string has a non-explicit constructor that accepts a char* (it interprets the pointed-to data as a null-terminated C string). Thus you can put in the name of an array of char and that works too, because of pointer decay.

This does not work the other way around. However, SDL_WM_SetCaption accepts a const char*, i.e. it promises not to change the pointed-at characters. This means you are in luck. All you need to do is call the .c_str() member function of the string when you call the function. For an example, go back to the thread you mentioned, and scroll down to my post.

It might also be that NULL is not valid for the 'icon' parameter. Try passing the same string for both parameters.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!