Go to Post There are always rules we don't agree with, just like in life. Our character is defined by how we respond. - Mr MOE [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-03-2005, 14:10
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Why printf?

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?
__________________
http://www.mikesorrenti.com/
  #2   Spotlight this post!  
Unread 20-03-2005, 14:40
Unsung FIRST Hero
Greg Marra Greg Marra is offline
[automate(a) for a in tasks_to_do]
FRC #5507 (Robotic Eagles)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2005
Location: San Francisco, CA
Posts: 2,031
Greg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond repute
Re: Why printf?

Quote:
Originally Posted by MikeWasHere05
Can you use print() in c? If so why doesn't FIRST?
I am not sure that C has a print() function. If it did, it would be functionally identical to printf, I imagine. PHP is an entirely different language than C, and they have different syntax and commands and functions.

Don't forget, not all computers have the same outputs, so you can 'print' to several different things (a printer, a serial connection, a monitor).
  #3   Spotlight this post!  
Unread 20-03-2005, 15:08
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Why printf?

PHP is an interpreted language, but C is compiled. In C, everything in between the quotes is stored verbatim in the binary image that gets executed. By the time the program is compiled, your program no longer knows what the variable names were so it could not parse the variables out of the string. Even if it did know the variable names, it would need special knowledge of where the variable was actually stored.

I can't think of any way that it would even be possible to do this in C without doing some pre-processing before it got to the compiler.
  #4   Spotlight this post!  
Unread 20-03-2005, 15:10
Validius's Avatar
Validius Validius is offline
There is a shadow following me.....
AKA: Mark Ratering
FRC #1549 (Washtenuts)
Team Role: College Student
 
Join Date: Feb 2005
Rookie Year: 2005
Location: South Lyon
Posts: 159
Validius will become famous soon enoughValidius will become famous soon enough
Send a message via AIM to Validius
Re: Why printf?

printf is print formatted

I know that in perl there is both print and printf but printf is far more powerfull
__________________
When a sociaty comes to believe that human life is not inherently worth living, it is a slippery slope to the gas chamber. You wind up on a low road that twists past Columbine and leads toward Auschwitz.

-Peggy Noonan
  #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
  #6   Spotlight this post!  
Unread 20-03-2005, 15:54
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Re: Why printf?

Thanks guys, I just wasn't too sure.
__________________
http://www.mikesorrenti.com/
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printf Oddity : Programming Challange DarkAlex Programming 7 21-03-2005 08:12
printf statements do not display in autonomous mode PVC Pirates Programming 3 22-02-2005 15:41
Default Code and printf WilsonDJ00 Programming 2 22-01-2005 16:39
Anyone with a replacement Printf? Larry Barello Programming 5 19-03-2004 02:20
Printf warning during compile? actorindp Programming 4 20-02-2004 17:02


All times are GMT -5. The time now is 23:00.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi