alloc using the memory manager, there is a talk about allocking (correctly
spelled? I dont think so), I will give you a complete example:
thats better of defining static becouse when you free them, you are really
liberating the memory as you don't with statics.
#include <stdarg.h>
void StrNPrintF(CharPtr s,UInt size, CharPtr formatStr, ...)
{
va_list args;
// Char text[size];
// Instead of using a local array, use a pointer
char *text;
// Alloc
if ( ( text = MemPtrNew(size) ) == NULL) {
// MALLOC_ERROR
return; // You may change the void result for an int and return a
custom errorNumber
}
va_start(args, formatStr);
StrVPrintF(text, formatStr, args);
va_end(args);
StrNCopy(s, text, size);
// Ready, Free the pointer
MemPtrFree(text);
}
Hope it helps, Ariel
----- Original Message -----
From: Charles Rezsonya <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 01, 2000 10:55 AM
Subject: Re: StrPrintF
> alloc using what? if this is using some of the dmMemPtr__ api call's,
can
> you provide an example? the way i prevent stack problems at the moment is
> by declaring some static.
>
> -----Original Message-----
> From: Ariel Barreiro <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: Tuesday, January 04, 2000 2:46 AM
> Subject: RE: StrPrintF
>
>
> >you can build our own StrNPrintF fuction, with the StrVPrintF, the code
> >would be something like this:
> >
> >#include <stdarg.h>
> >void StrNPrintF(CharPtr s,UInt size, CharPtr formatStr, ...)
> >{
> >va_list args;
> >Char text[size];
> >va_start(args, formatStr);
> >StrVPrintF(text, formatStr, args);
> >va_end(args);
> >StrNCopy(s, text, size);
> >}
> >
> >hope this might give you and idea, you also shoud alloc the memory
instead
> >of creating a local buffer in order not to overflow the stack.
> >
> >Ariel.
> >
> >
> >----- Original Message -----
> >From: Charles Rezsonya <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Friday, December 31, 1999 11:18 AM
> >Subject: StrPrintF
> >
> >
> >> the use of StrPrintF is quite nice, i have some message construction
> used
> >> in a protocol and stuff, but i find it sorrowing that i can't utilize
> the
> >> N. as an example, if i was to do strCat's or StrCopy's i can protect
> >> myself more with StrNCat's and StrNCopy's, but there are no
> StrNPrintF's.
> >> has anyone or does anyone have a good idea to use StrPrintF but have a
N
> >> equivilent (or any related call's?)
> >>
> >>
> >>
> >>
> >
> >
>
>
>
>
>