Skip to main content
GameDev.net gamedev.net
🔒 Locked

Small question

Started by Fender148 Jul 5, 2000 at 5:53 PM 3 replies 200+ views
Original Post
Fender148
Fender148
I know a decent amount of C++, but the book Im now reading uses printf and sprintf from time to time and I''m not sure what they''re for. A little explanation would be great. Thanks
JonatanHedborg
JonatanHedborg
I HOPE you know what printf does...

printf("Hello world\n"); will printf out Hello world on your screen.

sprintf prints, instead of the screen, to a buffer (could be a char*)

========================
Game project(s):
www.fiend.cjb.net
================<FONT COLOR="#850000
Jaspring
Jaspring
The printf() family of Input/output functions came from the C standard library.
Fender148
Fender148
Thanks, I never saw printf before I always used cout
ImmaGNUman
ImmaGNUman
printf is a function that prints out formatted output to stdio, the C standard input/output stream, sprintf is formatted output to a buffer. Both have variable lengths.

E.g.

printf("The square root of %d is %d.", number, othernumber);

sprintf(buffer, "%s", string);

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.