Thread: Contradictory outputs

  1. #31
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Quoting the standard:
    Quote Originally Posted by c99 draft, fopen()
    When a file is opened with update mode (’+’ as the second or third character in the
    above list of mode argument values), both input and output may be performed on the
    associated stream. However, output shall not be directly followed by input without an
    intervening call to the fflush function or to a file positioning function (fseek,
    fsetpos, or rewind), and input shall not be directly followed by output without an
    intervening call to a file positioning function, unless the input operation encounters end-
    of-file. Opening (or creating) a text file with update mode may instead open (or create) a
    binary stream in some implementations.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #32
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    Thats what am asking sir.. Why can't output be directly followed by input??

  3. #33
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Because some systems may choose to implement an input buffer and and output buffer. This works great, if all you're doing is input OR output.
    But if you're doing input AND output, then some kind of synchronisation event (say seek or flush) is needed to restore consistency between the two.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #34
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    But, why do we need some external synchronisation event to restore consistency. Whats disturbing the consisitency in the first place??

  5. #35
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    Got it... Thank you.

  6. #36
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    It is possibly concerned with how electronic buffers behave, something concerned with electronics and not C...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Different outputs on different OS
    By darksifer in forum C Programming
    Replies: 13
    Last Post: 10-19-2010, 01:45 PM
  2. why i getting different outputs?
    By nkrao123@gmail. in forum C Programming
    Replies: 2
    Last Post: 12-08-2009, 08:33 AM
  3. Outputs
    By kas2002 in forum C++ Programming
    Replies: 3
    Last Post: 10-29-2002, 07:12 PM
  4. Replies: 28
    Last Post: 08-21-2002, 05:30 PM
  5. contradictory if statements
    By red_baron in forum C Programming
    Replies: 13
    Last Post: 05-04-2002, 06:52 PM