[En-Nut-Discussion] Who can answer me on sprintf problem ?
ivesworking at hotmail.com
Sun Jul 9 12:54:27 CEST 2006
Thanks for your answer, it seem better and should be more stable.
Got another question is similar, but more trouble, [i feel like i am not a
if i want to trim some string from know format,
assume my string is "<data:helloworld>"
and i want to let my string become "helloworld"
if assume the string store at char *buf;
what i plan to do is strncpy(buf,buf+6,strlen(buf)+6+1)
i know we can do it in the long way, like declare another buffer,
but is that possible to do it in this short way ?
----- Original Message -----
From: "Brett Abbott" <Brett.Abbott at digital-telemetry.com>
To: "Ethernut User Chat (English)" <en-nut-discussion at egnite.de>
Sent: Sunday, July 09, 2006 7:58 AM
Subject: Re: [En-Nut-Discussion] Who can answer me on sprintf problem ?
> 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.
> ivesworking wrote:
>> I was apply this a lot of sprintf technic on theboard, till on old 3.4
>> 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
> 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 --------------------
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
More information about the En-Nut-Discussion