Ive learned how to use the debugger and ive found that sprintf() is the root of all the access violations im getting.
is there another simple function that can do about the same thing?
Ive learned how to use the debugger and ive found that sprintf() is the root of all the access violations im getting.
is there another simple function that can do about the same thing?
A) Do you have enough memory allocated for the buffer?
B) You can use stringstreams.
>Ive learned how to use the debugger and ive found that sprintf() is the root of all the access violations im getting.
Perhaps your use of sprintf is the root of your access violations, but I seriously doubt that sprintf itself is to blame. Show us your code and we'll see if there's a problem you aren't seeing.
-Prelude
My best code is written with the delete key.
OK, I dont think my standard library is 'broken', the program runs fine unless debugging, where my call to sprintf
sprintf(strLoadCard, "Cards Loaded = %i Percent", cards);
calls to write_char in OUTPUT.C (A standard library file) where an access violation occurs
cards is a integer that has been initilized and has a current value of 0; strLoadCard has been declared in the objects constructor as
strLoadCard = new char[500];
strLoadCard = "";
in the destructor I have this
delete [] strLoadCard;
and the object its self has this as a member
char* strCardLoad;
this is the function where the error occurs for what its worth
LOCAL(void) write_char (
int ch,
FILE *f,
int *pnumwritten
)
{
if (_putc_lk(ch, f) == EOF) <<< Unhandled Exception - Access Violation
*pnumwritten = -1;
else
++(*pnumwritten);
}
strLoadCard = "";
this is a problem. U have gotten a pointer to a dynamically sized piece of memory then you repoint it to a static string containing just a null byte. You have lost the memory u got from new by doing this.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
duh. I know that, I cant believe I actually posted this....
To make it worthwhile, can anyone tell me how I can use the debugger to track any memory leaks?
Last edited by Eber Kain; 12-27-2002 at 10:42 PM.