open, fopen ?

This is a discussion on open, fopen ? within the C Programming forums, part of the General Programming Boards category; Hey, one can use fopen to write/read binary data to/from a file. The same can also be achieved by using ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    4

    open, fopen ?

    Hey,

    one can use fopen to write/read binary data to/from a file.
    The same can also be achieved by using open.

    What exactly are the differences?

    As far as I know fopen is standard C and platform independent, right? It also its a buffered I/O.
    open on the other hand is declared in different headers for different platforms and its low level (unbuffered) I/O. And therefor should be faster?

    Any additional comments or corrections are welcome.

    Mat.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > As far as I know fopen is standard C and platform independent, right?
    Yes.

    > It also its a buffered I/O.
    By default, yes.
    See also setvbuf()

    > open on the other hand is declared in different headers for different platforms
    And the parameters sometimes vary as well.

    > And therefor should be faster?
    Probably - but the difference between the two is seldom exciting enough to sacrifice portability.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Using low-level I/O can be slower if you use it incorrectly. Calls to read()/write() are much slower than calls to fread()/fwrite()/fprintf()/etc. (which is the purpose for the buffer in the first place). If you're reading/writing data in large chunks, the low-level I/O is usually faster, but for reading/writing data in smaller bits the stdio routines are faster.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fopen can't open .exe?
    By fanoliv in forum C Programming
    Replies: 11
    Last Post: 04-05-2011, 03:24 PM
  2. Diff bet fopen() & open()
    By ankurcse in forum C Programming
    Replies: 2
    Last Post: 05-24-2006, 09:40 AM
  3. fopen() and open()
    By Encrypted in forum C Programming
    Replies: 8
    Last Post: 02-09-2003, 03:57 PM
  4. fopen vs open
    By rotis23 in forum Linux Programming
    Replies: 5
    Last Post: 12-10-2002, 01:30 PM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21