hercules <we*****@harbournetworks.com> wrote in message
news:bd***********@mail.cn99.com...

You may use the function named "sprintf" . U had better use the function named "snprintf"

snprintf is more security than sprintf

And of course be mindful of the fact that unless you have a C99 compiler,
snprintf is non-standard. For example, you have to use _snprintf on MSVC.
In cases like that, you might want to do what I did, which is to have a
header that (among other things) #defines snprintf _snprintf.

Alternatively (and much more involved, so I haven't done it) is to rename
the headers in your compiler's include directory. Then, write a header with
the old name which includes the renamed header, followed by the C99
enhancements. Actually, it would be nice if somebody wrote a patch that did
that to MSVC's include directory to make it C99 compliant wherever possible.

Of course, many of the changes, like the snprintf problem, inttypes.h, and
iso646.h, are trivial. Others, such as complex.h are difficult or
impossible; barring hacks to the compiler itself.

<su**********@wipro.com> wrote in message news:94**************************@posting.google.c om...

You can use sprintf function to achieve that.

sprintf (string, "%s%d", string, number);

I HATE having sprintf() write over one of its arguments. I don't believe (any comments?) that it is legal, either, though it often seems to work.

It is undefined behavior, see C99 7.19.6.6 "The sprintf
function":

If copying takes place between objects that overlap, the
behavior is undefined.
Consider, for example, sprintf(string,"%f",cray_number) when running on a Cray with 64 bit floating point format with 16 bits of exponent. How big should string be?

Difficult to say, so snprintf() would be preferable.
--
"This is a wonderful answer.
It's off-topic, it's incorrect, and it doesn't answer the question."
--Richard Heathfield