View Single Post
Old 01-18-2004, 10:12 AM   #1
Sitral
New Member
 
Join Date: Apr 2002
Posts: 11
Sitral is on a distinguished road
It seemed like a simple idea, free and allocate a string in the same function and make it user friendly.  Is it possible to free/malloc through a pointer?  This's roughly what I'd like to do:
[code] void osprintf( char *target, char *string )
{
   if( target != NULL ) { free( target ); target = NULL; }
   target = (char *) malloc( strlen(string) );
   sprintf( target, string );
   return;
}[/quote]
But this only impacts the local incarnation of target (with the exception of free?).  I've exhausted my knowledge and creativity and the best I've been able to do is make the function a char-pointer and return target, but the syntax just isn't as appealing.  Any advice, or am I asking for the impossible?
Sitral is offline   Reply With Quote