[En-Nut-Discussion] Who can answer me on sprintf problem ?

Brett Abbott Brett.Abbott at digital-telemetry.com
Sun Jul 9 08:58:50 CEST 2006


Wfloh

 From first glance, as long as you always have the %s at the start of 
the format string, it looks like a nice way to append data to a string.  
Having said that, it clearly doesnt work for you anymore.....

I use ICC so cant comment on gcc but it may be possible that the 
implementation of the compiler doesnt allow for the "unusual" construct.

I have been using the following mechanism to append to a string.  See if 
this works, it should do the same type of thing.

sprintf(buffer+strlen(buffer), "helloworld %d %d ", data1,data2);   You 
may find it more efficient.

Cheers
Brett
ivesworking wrote:
> I was apply this a lot of sprintf technic on theboard, till on old 3.4 
> OS,
> i know this should be more like gcc question,
>
> i processing some word on cgi,
> to avoid declare too many buffer using malloc, i thinking of declare 
> one large block of mem as buffer
> then using sprintf to add content into it, (due to the content i want 
> will be in format, so sprintf is a good tools )
>
> however sprintf will wipe out the original content, as strcpy do,
> so i program with
> sprintf(buffer,"%shelloworld %d %d ", buffer, data1,data2);
> i able to perform this task without complain from the compiler and it 
> was running on the board fine,
> to avoid future problem, i need someone confirm with me this method is 
> usable in standard gcc which compiler know how to handle this kind of 
> technic, or this is technically not allow due to it point back to the 
> same place,
>
>
> Wfloh _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>
>

-- 
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------





More information about the En-Nut-Discussion mailing list