Converting Double to Char Array

Started by
5 comments, last by Zahlman 13 years, 9 months ago
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]
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!
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]
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.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

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>?
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.
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.

This topic is closed to new replies.

Advertisement