Santa are u there .....
Merry Christmas guys
Got a problem .....
string s = "santa";
char *title = new char[ s.length() ];
s.copy( title, s.length() );
if (!CreateGLWindow(title,640,480,16,fullscreen))
the problem is the title of the window becomes santayyyy
the y''s have 2 dots on top of them too!.
they sometimes go away when i do
char *title = new char[ s.length()-4 ];
anybdy....?thnx
I believe the source of your problem lies in the way you create your character array. You should set the array to "s.length()+1"
Strings in C/C++ need a null byte at the end of them, and so you need 1 extra byte of space for this character.
I hope this is the correct information.
Merry xmas!
/**************************************
* Hookt on Fonix relly werked fer mee!
* WarAmp
***************************************/
Strings in C/C++ need a null byte at the end of them, and so you need 1 extra byte of space for this character.
I hope this is the correct information.
Merry xmas!
/**************************************
* Hookt on Fonix relly werked fer mee!
* WarAmp
***************************************/
Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
May I ask you: why are you typing so much code (and wasting CPU cycles) for getting a name into a char pointer? (or however you call those types )
// Why don''t you do this?char title[256];sprintf(title,"santa");if (!CreateGLWindow(&title,640,480,16,fullscreen))
quote: Original post by richardve
May I ask you: why are you typing so much code (and wasting CPU cycles) for getting a name into a char pointer? (or however you call those types )
The same applies to you, though... and you are mistakenly passing the address of a pointer to a character array as first argument...
[home page] [e-mail]
---
"Lifting shadows off a dream once broken
She can turn a drop of water into an ocean"
---[home page] [[email=karmalaa@inwind.it]e-mail[/email]]
abt th reason why im typing so much..
that piece of code was just a test. I actually want to use the string template but since windows requires char* for some API calls, i was trying out the conversion from string to char*
thanz guys but still doesnt work
but abt the byte thing ... this works
string s = "santa";
char *title = new char[ s.length()-4 ];// ADDING -4 MAKES IT PRINT CORRECTLY
s.copy( title, s.length() );
if (!CreateGLWindow(title,640,480,16,fullscreen))
however even this fails at times depending upon the length of the string s
?ideas?
that piece of code was just a test. I actually want to use the string template but since windows requires char* for some API calls, i was trying out the conversion from string to char*
thanz guys but still doesnt work
but abt the byte thing ... this works
string s = "santa";
char *title = new char[ s.length()-4 ];// ADDING -4 MAKES IT PRINT CORRECTLY
s.copy( title, s.length() );
if (!CreateGLWindow(title,640,480,16,fullscreen))
however even this fails at times depending upon the length of the string s
?ideas?
I beleive that the command s.length() is returning the number of characters in the string and not including the null terminator! so you'd have to put s.lenght()+1
Edited by - avianRR on December 24, 2000 11:57:02 PM
Edited by - avianRR on December 24, 2000 11:57:02 PM
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
I may be new to c++, but I think I know what you're looking for:
Hope that helps
------------------------------------------------
SkyFire360
"The beaver killed the beaver! I am so stupid!"
Current Project: MD3 Loader
Project Status: Can Load the mesh and animate it
Edited by - skyfire360 on December 24, 2000 12:44:18 AM
string s = "santa"; char *title;title = (char *) malloc(sizeof(s));s.copy( title, s.length() );if (!CreateGLWindow(title,640,480,16,fullscreen))//try that//or//the always easier:char s[255] = "santa"; char *title;title = (char *) malloc(sizeof(s));strcpy( title, s); // you can substitute sprintf here too I thinkif (!CreateGLWindow(title,640,480,16,fullscreen))
Hope that helps
------------------------------------------------
SkyFire360
"The beaver killed the beaver! I am so stupid!"
Current Project: MD3 Loader
Project Status: Can Load the mesh and animate it
Edited by - skyfire360 on December 24, 2000 12:44:18 AM
I do real things with imaginary numbers
quote:
Original post by karmalaa
---
The same applies to you, though... and you are mistakenly passing the address of a pointer to a character array as first argument...
Hehe , that''s why I never code when it''s late.. too many bugs and typos!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement