AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   [RESOLVED] sprintf problem .... (https://forums.alliedmods.net/showthread.php?t=128497)

neo_gis 06-01-2010 18:14

[RESOLVED] sprintf problem ....
 
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 ?

pRED* 06-01-2010 20:53

Re: sprintf problem ....
 
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.

neo_gis 06-02-2010 05:12

Re: sprintf problem ....
 
yh i figured it out later after some pain :P . finally got it to work using vsnprintf and va_list .


All times are GMT -4. The time now is 07:09.

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