Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > puts vs fputs

Reply
Thread Tools

puts vs fputs

 
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      07-20-2012
Is there any logic behind puts() adding a newline but fputs() not doing it?
Or was it just a design **** up in the early days of C?

B2003

 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      07-20-2012
Le 20/07/12 11:15, http://www.velocityreviews.com/forums/(E-Mail Removed) a écrit :
> Is there any logic behind puts() adding a newline but fputs() not doing it?
> Or was it just a design **** up in the early days of C?
>
> B2003
>


The standard output stream is line buffered by default, i.e. it will
never output something unless it sees a carriage return. That is why
puts() that writes its output to standard output needs a new line.

fputs() doesn't need a new line since the stream is in most cases not
the standard output and it is buffered, not line buffered.

Before treating things like that as "design ****ups" try to understand
why they are so designed.

jacob

 
Reply With Quote
 
 
 
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      07-20-2012
On Fri, 20 Jul 2012 12:38:37 +0200
jacob navia <(E-Mail Removed)> wrote:
>The standard output stream is line buffered by default, i.e. it will
>never output something unless it sees a carriage return. That is why
>puts() that writes its output to standard output needs a new line.
>
>fputs() doesn't need a new line since the stream is in most cases not
>the standard output and it is buffered, not line buffered.


Thats not a good enough reason for the inconsistent behaviour IMO.

>Before treating things like that as "design ****ups" try to understand
>why they are so designed.


I didn't, I asked whether it was one. Perhaps your understanding of english
isn't as good as you think.

B2003


 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      07-20-2012
Le 20/07/12 12:41, (E-Mail Removed) a écrit :
> On Fri, 20 Jul 2012 12:38:37 +0200
> jacob navia <(E-Mail Removed)> wrote:
>> The standard output stream is line buffered by default, i.e. it will
>> never output something unless it sees a carriage return. That is why
>> puts() that writes its output to standard output needs a new line.
>>
>> fputs() doesn't need a new line since the stream is in most cases not
>> the standard output and it is buffered, not line buffered.

>
> Thats not a good enough reason for the inconsistent behaviour IMO.
>


If you do not put the new line, when you write:

puts("Please enter a number");

you will not see anything...


Thats a good enough reason for the inconsistent behaviour IMO.

 
Reply With Quote
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      07-20-2012
On Fri, 20 Jul 2012 12:54:27 +0200
jacob navia <(E-Mail Removed)> wrote:
>Le 20/07/12 12:41, (E-Mail Removed) a écrit :
>> On Fri, 20 Jul 2012 12:38:37 +0200
>> jacob navia <(E-Mail Removed)> wrote:
>>> The standard output stream is line buffered by default, i.e. it will
>>> never output something unless it sees a carriage return. That is why
>>> puts() that writes its output to standard output needs a new line.
>>>
>>> fputs() doesn't need a new line since the stream is in most cases not
>>> the standard output and it is buffered, not line buffered.

>>
>> Thats not a good enough reason for the inconsistent behaviour IMO.
>>

>
>If you do not put the new line, when you write:
>
>puts("Please enter a number");
>
>you will not see anything...
>
>
>Thats a good enough reason for the inconsistent behaviour IMO.


Really, so why didn't they use the same logic with the printf functions then?
Why didn't they specify printf() to do an automatic newline but fprintf() not?

B2003

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      07-20-2012
Le 20/07/12 13:13, (E-Mail Removed) a écrit :
> why didn't they use the same logic with the printf functions then?
> Why didn't they specify printf() to do an automatic newline but fprintf() not?


Because printf is a run time interpreter of its format string.

When you use printf you do want EXACT control of the output,
not just put a string (puts) in the screen, adding a new line
would break the precise formatting instructions.

Puts(string) is equivalent to printf("%s\n", string);

jacob
 
Reply With Quote
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      07-20-2012
On Fri, 20 Jul 2012 14:23:04 +0200
jacob navia <(E-Mail Removed)> wrote:
>Le 20/07/12 13:13, (E-Mail Removed) a écrit :
>> why didn't they use the same logic with the printf functions then?
>> Why didn't they specify printf() to do an automatic newline but fprintf()

>not?
>
>Because printf is a run time interpreter of its format string.
>
>When you use printf you do want EXACT control of the output,
>not just put a string (puts) in the screen, adding a new line
>would break the precise formatting instructions.


You're just making this up as you go along arn't you? Your argument lacks
any logic whatsoever. A family of functions should have consistent
functionality. End of.

B2003


 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      07-20-2012
Le 20/07/12 14:54, (E-Mail Removed) a écrit :
> On Fri, 20 Jul 2012 14:23:04 +0200
> jacob navia <(E-Mail Removed)> wrote:
>> Le 20/07/12 13:13, (E-Mail Removed) a écrit :
>>> why didn't they use the same logic with the printf functions then?
>>> Why didn't they specify printf() to do an automatic newline but fprintf()

>> not?
>>
>> Because printf is a run time interpreter of its format string.
>>
>> When you use printf you do want EXACT control of the output,
>> not just put a string (puts) in the screen, adding a new line
>> would break the precise formatting instructions.

>
> You're just making this up as you go along arn't you? Your argument lacks
> any logic whatsoever. A family of functions should have consistent
> functionality. End of.
>
> B2003
>
>


OK. Look, you are unhappy?

Please complain to the committee. I can only give you the reasons why
this is so.

Should be changed?

Maybe, personally I do not mind about the extra newline of puts() since
I seldom use it.

End of story.

 
Reply With Quote
 
Anders Wegge Keller
Guest
Posts: n/a
 
      07-20-2012
jacob navia <(E-Mail Removed)> writes:

> Please complain to the committee. I can only give you the reasons
> why this is so.


Not really. It looks more like your own guesses.

Take a look at
<http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf>


7.19.7.10 The puts function
puts(s) is not exactly equivalent to fputs(stdout,s); and puts also
writes a newline after the argument string. This incompatibility
reflects existing practice.

--
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*
 
Reply With Quote
 
Mark Storkamp
Guest
Posts: n/a
 
      07-20-2012
In article <(E-Mail Removed)>,
Anders Wegge Keller <(E-Mail Removed)> wrote:

> jacob navia <(E-Mail Removed)> writes:
>
> > Please complain to the committee. I can only give you the reasons
> > why this is so.

>
> Not really. It looks more like your own guesses.
>
> Take a look at
> <http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf>
>
>
> 7.19.7.10 The puts function
> puts(s) is not exactly equivalent to fputs(stdout,s); and puts also
> writes a newline after the argument string. This incompatibility
> reflects existing practice.


How is that different than what Jacob (with more patience than I have)
explained? All you quoted was that it 'reflects existing practice'.
Jacob explained why that practice existed.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about fputs() Chad C Programming 17 06-23-2008 08:44 PM
what's the diff between puts y and puts "#{y}" in class_eval Raj Singh Ruby 4 01-29-2008 10:16 PM
Suggestion: swap name of "puts" and "print" and rename "puts" to"put_s" Michael Brooks Ruby 22 03-27-2007 04:57 PM
seek and fgets and fputs fopen dave C++ 4 11-02-2006 10:10 PM
Problem in Writing into the file..using fputs() call xoinki C Programming 1 05-02-2006 01:14 PM



Advertisments