Thread: Why printf?
View Single Post
  #5   Spotlight this post!  
Unread 20-03-2005, 15:44
jdiwnab's Avatar
jdiwnab jdiwnab is offline
Really the Inventor Guy
AKA: Bryan Hartley
FRC #0617
Team Role: College Student
 
Join Date: Nov 2004
Rookie Year: 2002
Location: Highland Springs, VA
Posts: 260
jdiwnab is a jewel in the roughjdiwnab is a jewel in the roughjdiwnab is a jewel in the rough
Re: Why printf?

Quote:
Originally Posted by MikeWasHere05
Why do we use printf? I started c at the beginning of 6 weeks (minus about a week of c++), but knew PHP before that. In PHP you use the print statement where you just go
Code:
<?php
print "The variables value is: $variable";
?>
whereas in c you have to write
Code:
printf("The variables value is: %d", variable);
Can you use print() in c? If so why doesn't FIRST?
There isn't much of a difference between how the two functions are coded. Print() has the varible listed in the string. Printf() has the varible outside of the string. They work about the same. One difference is the d in %d could also be %f for floats and other things like that. This lets you say the type of varible you think you are going to see. It could truncate a long float if you don't need to see all of it. Or other things like that. Printf() is more powerful, and is coded about the same. Printf() just adds one more step.
__________________
Proof that Macs will win the platform war: How did Scotty know how to use MacDraft in Star Trek IV?
// random()
I have 100 gmail invites. PM me if you want one.
If they want us to think outside of the box, why do they make us fit in a 38x28x60 inch box?
Beware of Geeks bearing GIFs
Help me test my server software