Raised This Month: $32 Target: $400
 8% 

[RESOLVED] sprintf problem ....


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
neo_gis
Member
Join Date: Sep 2009
Location: Rabat
Old 06-01-2010 , 18:14   [RESOLVED] sprintf problem ....
Reply With Quote #1

Code:
    
int i = 15;

char *msg;
    
sprintf(msg, "i = %d", i);
When i try this on devC++ as console app it works but on my server plugin it crashes !

anyhelp on this one ?
__________________

Last edited by neo_gis; 06-02-2010 at 11:35.
neo_gis is offline
Send a message via MSN to neo_gis Send a message via Skype™ to neo_gis
pRED*
Join Date: Dec 2006
Old 06-01-2010 , 20:53   Re: sprintf problem ....
Reply With Quote #2

I'd suggest doing some introductory c++ work before jumping into writing a server plugin.

char *msg is only creating a pointer to a string, not a buffer to hold an actual string. And then as a bonus, it's uninitialized.

Like a handle without a cup. And you're now pouring coffee on the floor.
pRED* is offline
neo_gis
Member
Join Date: Sep 2009
Location: Rabat
Old 06-02-2010 , 05:12   Re: sprintf problem ....
Reply With Quote #3

yh i figured it out later after some pain . finally got it to work using vsnprintf and va_list .
__________________
neo_gis is offline
Send a message via MSN to neo_gis Send a message via Skype™ to neo_gis
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode