473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

open,fopen differences

Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #1
13 22575
Blue wrote:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).


From a C perspective, the difference is simple: fopen(), fread(),
fwrite(), etc. exist, the rest do not.

If you want to write portable code, use fopen(), etc. [1]

HTH,
--ag

[1] Of course, if you *need* to use whatever platform specific lower
level primitives exist on your platform, by all means do so -- but
further questions about them will be off topic here.

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Nov 14 '05 #2
Artie Gold <ar*******@austin.rr.com> wrote in news:3amqrcF6e6uaqU1
@individual.net:
Blue wrote:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).


From a C perspective, the difference is simple: fopen(), fread(),
fwrite(), etc. exist, the rest do not.

If you want to write portable code, use fopen(), etc. [1]

HTH,
--ag

[1] Of course, if you *need* to use whatever platform specific lower
level primitives exist on your platform, by all means do so -- but
further questions about them will be off topic here.

fopen/fread/fwrite have buffer to fasten I/O process, but open/read/write
dosen't

Nov 14 '05 #3
On Sun, 27 Mar 2005 06:12:15 +0000 (UTC), bigben <bi****@galaway.com>
wrote in comp.lang.c:
Artie Gold <ar*******@austin.rr.com> wrote in news:3amqrcF6e6uaqU1
@individual.net:
Blue wrote:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?

Thank you.

Cheers,
Blue :).


From a C perspective, the difference is simple: fopen(), fread(),
fwrite(), etc. exist, the rest do not.

If you want to write portable code, use fopen(), etc. [1]

HTH,
--ag

[1] Of course, if you *need* to use whatever platform specific lower
level primitives exist on your platform, by all means do so -- but
further questions about them will be off topic here.

fopen/fread/fwrite have buffer to fasten I/O process, but open/read/write
dosen't


Where in the ISO C standard does it state what "open", "read" and
"write" do? Nowhere, because such functions are not even defined.
They do whatever the implementation says they do, and whatever that is
it is not a C matter.

What if the "open" function on some platform popped out the tray on
the CD drive? What in the C standard prohibits it?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
in the au jus.

Bisque à l?Enfant

Honor the memory of Grandma with this dish by utilizing her good
silver soup tureen and her great grandchildren (crawfish, crab or
lobster will work just as well, however this dish is classically
made with crawfish).

Stuffed infant heads, stuffed crawfish heads, stuffed crab or lobster shells;
make patties if shell or head is not available
(such as with packaged crawfish, crab, or headless baby).
Flour
oil
onions
bell peppers
garlic salt, pepper, etc.
3 cups chicken stock
2 sticks butter
3 tablespoons oil

First stuff the heads, or make the patties (see index)
then fry or bake.
Set aside to drain on paper towels.
Make a roux with butter, oil and flour,
brown vegetables in the roux, then add chicken stock and
allow to simmer for 20 minutes.
Add the patties or stuffed heads, and some loose crawfish,
lobster, long piglet, or what have you.
Cook on low for 15 minutes, then allow it to set for at least
15 minutes more.
Serve over steamed rice; this dish is very impressive!

Stuffed Cabbage Rolls

Babies really can be found under a cabbage leaf -
or one can arrange for ground beef to be found there instead.

8 large cabbage leaves
1 lb. lean ground newborn human filets, or ground chuck
Onions
peppers
celery
garlic
soy sauce
salt pepper, etc
Olive oil
breadcrumbs
Tomato Gravy (see index)

Boil the cabbage leaves for 2 minut
Nov 14 '05 #5
>Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".
fopen(), fread(), and fwrite() are present in ANSI C. open(),
read(), and write() are not, but they are present in POSIX.
I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.
On a particular implementation, this may be correct. In general,
the line between "system calls" and "library functions" is fuzzy
at best and meaningless at worst.
May be internally must be calling "fopen" /"fread" / "fwrite"
functions.
Parse sense no.
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


ANSI C is more portable than POSIX. DO NOT try to mix the two sets.
The representation of an "open file handle" or whatever you call
it is very different between open() and fopen().

Gordon L. Burditt
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #6
Blue wrote:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.
fopen/fclose/fread/fwrite are C standard library functions.

open/close/read/write _may_ be functions provided by your operating
systems or come from somewhere else -- or they might not be there
at all; they are not standard C.

If you want your programs to be portable or as portable as possible,
restrict yourself to the standard library (whenever possible).

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.
It is possible that internally fopen() & Co. use open() and
friends if available.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


If you want file access functions and the standard library functions
are sufficient for your purposes, then use them. Only if the other
functions provide something you cannot get using the standard library,
use the other functions.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #7
Blue wrote:
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


open() is not standard and might not be implemented in
some standard-conforming hosted environments, whereas
fopen() is standard and is implemented in all standard-
conforming hosted environments. Therefore for
portability, use the standard functions, not (emulated)
Unix system service calls.

There are other functional differences, the most
notable being that the stdio stream uses a buffer in
"user space", whereas the direct system-call I/O does
not. (There might or might not be kernel-space
buffers in both cases.) This can matter if record
length is important; for example, if you want to write
a magnetic tape record of length 80, write(fd,buf,80)
will do that, whereas fwrite(buf,80,1,fp) will likely
just put the data in a user-space buffer, with the
actual write occurring eventually when the buffer is
full - which will result in something like a 512-byte
magtape record. You could perhaps work around that by
issuing a fflush(fp) after the fwrite(), but it's a
kludgy way to accomplish what write() does directly.
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #8
Blue wrote:

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.


No you don't. You know that fopen, fread, fwrite, fclose are
available because the standard says they must be. You KNOW
absolutely nothing about open, read, write, because the standard
says nothing about them. They may be present on some systems, in
some form or other, but that has nothing to do with the C
language. You would be well advised to ignore them unless forced
into building some non-portable non-standard peculiar software.

Because open, read, write etc. are non-standard, they are off-topic
here. They may well be topical on a newsgroup dedicated to your
particular system.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #9
Blue wrote:
Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


(a) fopen() et al are standardized in the C standard; open() et al are
standardized by POSIX. There are more standard C platforms than POSIX
platforms, so fopen() et al are more portable (if used carefully).

(b) fopen() et al deal with FILE * whereas open() et al use an integer.

(c) typically, open() in some variation is used by fopen() - the reason
for 'some variation' being that you are permitted (in standard C) to
write your own function called open() and the fopen() is not allowed to
call it instead of the system function.

(d) There are options that can be specified to open() that cannot be
specified to fopen(). If you need specialized control over the device,
you probably need to use open(). That said, you are immediately
limiting the portability of your application - because you require those
special semantics.

(e) Guideline: use fopen() et al until you find you can't do something.
Then work out how you can do it after all. Only if you really, really,
really can't do it, then drop into using open() etc.

--
Jonathan Leffler #include <disclaimer.h>
Email: jl******@earthlink.net, jl******@us.ibm.com
Guardian of DBD::Informix v2005.01 -- http://dbi.perl.org/
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #10
Blue wrote:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".
open, ... are part of POSIX. fopen, ... are part of the standard
libarary.

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.
Not sure what your saying is totally correct. This is discussed in
"The Standard C Library" by Plauger. It is probably worth your time to
read the section on stdio if you haven't already.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


Generally you should use fopen and friends because they are part of the
standard library. Also for most situations they will be faster. If
you are writing large amounts of data (multiple pages at a time) you
may want to consider using open and friends (but fread and fwrite do
fine in this case too).

-Charlie
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #11
In comp.lang.c.moderated Blue <ub**********@gmail.com> wrote:
Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".
The first element in each pair is a system-specific, non-portable
thing, the other is a properly standardized function of well-defined
behaviour.
But what difference does it makes from an application programmer
perspective?


The 'f' varieties allow you to write portable program's. What a
function called 'open()' might do on some random computer platform is
anyone's guess.

--
Hans-Bernhard Broeker (br*****@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #12
On Sun, 27 Mar 2005 03:10:33 +0000, Blue wrote:
Hi ,

Can any one please let me explain me the diffrences between "open"/
"fopen" or "read"/"fread" or "write/fwrite".

I know that "open" /"read" / "write" are system calls and "fopen"
/"fread" / "fwrite" are normal library functions.

May be internally must be calling "fopen" /"fread" / "fwrite"
functions.

But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


Well, you've pretty much covered it. open/read/close are POSIX system
calls, and are not portable to non POSIX systems, unlike f* ones. On unix
systems, open/read/write will be used internally, since there are the
operating system primitives for accessing files. Further, f* functions
provide buffering and formatted I/O, which the primitive calls do not do.

If you want portable C, use f* functions. If you need to access unix
functionality, like ioctl, mmap, tty mangling, etc, then you probably want
to use the unix primitives instead.

Also, some C libraries (I don'e believe this is standard, but I don't know
for sure), such as the GNU C one allow you to create custom FILE streams,
so you can read from things not natively represented by files on the
system (for instance, blocks of memory), which is a very, nice flexible
way of doing things.

-Ed

--
(You can't go wrong with psycho-rats.) (er258)(@)(eng.cam)(.ac.uk)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{10}d/r{roll}d f 5/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
for /s 15 d f pop 240 420 m 0 1 3 { 4 2 1 r sub -1 r show } for showpage
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #13
> May be internally must be calling "fopen" /"fread" / "fwrite"
functions.
Other way around -- fopen calls open, fread calls read, etc.
But what difference does it makes from an application programmer
perspective?Can any one please explain me about this ?


Application programmers normally don't need open and read, etc. Using
open and read gets you into system development issues, like restarting
system calls, buffered input/output, and all of that fun. The "f" class
functions take all of the dirty work away, while the other ones deal
directly with the operating system and all its ugliness.

You also have many more functions available with the "f" functions,
while with the open/read/write, that's pretty much all you get.

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
--
Copyright 2004, all wrongs reversed. Peter Seebach / se***@plethora.net
http://www.seebs.net/log/ - YA blog. http://www.seebs.net/ - homepage.
C/Unix wizard, pro-commerce radical, spam fighter. Boycott Spamazon!
Consulting, computers, web hosting, and shell access: http://www.plethora.net/
Nov 14 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Corne' Cornelius | last post by:
Hi, When you open a file for writing/appending with open() or fopen(), and you have multiple applications that might want to write to the same file at the same time, could that cause weirdness...
29
by: Tola | last post by:
In my case of study, my teacher gave me a project, after I analysed the problem I found that I had to used open the file on the other machine? Please help? Thank you in advance. Tola CHROUK
10
by: Grocery Clerk | last post by:
I know open() returns a file descriptor and fopen() returns a pointer to FILE. The question is, when do I use fopen() and when do I use open()? Could someone give me an example when to use one...
8
by: Asma | last post by:
Dear Sir, I am trying to find a way to open a Word document using C language and read the text of word doc into a variable. (Turbo C on Dos 6.0). Can anyone please tell me which libraries in...
4
by: Frank | last post by:
Could someone tell me how to open a file at run time that I didn't know the name of at compile time? I know how to open a file at compile time when I know what the name is going to be. FILE...
27
by: Jack | last post by:
What is the difference betweeb the two functions? Thanks.
4
by: Claire DURAND | last post by:
Hi, I try to open a distant (not local) XML file in PHP to read an RSS feed. I can open an HTML page and read it with the file() function. But as soon as I try with a RSS feed instead of...
5
by: chazzy69 | last post by:
The error : http://www.somesite.com Warning: fopen() : php_network_getaddresses: getaddrinfo failed: Name or service not known in /etc/etc/etc/etc/test.php on line 766 Warning:...
3
by: magicman | last post by:
Is difference lies in the fact that fopen part of c library and platform in-depended, whereas open is a system call? what about functionalities? thx
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.