Sprintf .....

E

Eric Sosman

Savio wrote On 09/30/05 13:29,:
Hi guys ,,

Can anyone out there tell me what is sprintf "

Like printf(), except that its "output" goes into a
character array that you provide instead of being sent
to stdout. The array must be large enough to hold all
the characters plus a terminating '\0'.
 
K

Keith Thompson

Savio said:
Hi guys ,,

Can anyone out there tell me what is sprintf "

SAvio

Does your C implementation include documentation? On any Unix-like
system, "man sprintf" should provide all the information you need; I
don't know about other systems.

Any decent book on C should explain sprintf. If you don't have a
decent C book, you should get one. Kernighan & Ritchie's _The C
Programming Language_, 2nd Edition, is an excellent tutorial.
Harbison & Steele's _C: A Reference Manual_, 5th Edition, is an
excellent reference.

You're posting through groups.google.com. You should be aware that
Google also provides an excellent web search engine.

There are all things you should try *before* posting to Usenet.
 
M

Mabden

Savio said:
Hi guys ,,

Can anyone out there tell me what is sprintf "

printf() writes a string to the output (the screen or whatever).
sprintf() writes one string into another string. Remember, you have to
allocate memory for the string you write to!

You use it to build a string you want to output later, so if you might
want to put the first name, then the last name, then the zodiac sign
into a string, you would use sprintf() to do it.
 
M

Michael Mair

Mabden said:
printf() writes a string to the output (the screen or whatever).
sprintf() writes one string into another string. Remember, you have to
allocate memory for the string you write to!

You use it to build a string you want to output later, so if you might
want to put the first name, then the last name, then the zodiac sign
into a string, you would use sprintf() to do it.

Apart from that: If you use a C99 implementation or if your standard
library contains the function, use snprintf() instead of sprintf()
as you can easier avoid buffer overflows and similar -- and have
a chance to find out that the output has been truncated.

See for example the excellent C99 library reference at dinkumware.com
for more information.


Cheers
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top