473,772 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 22634
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*******@aust in.rr.com> wrote in news:3amqrcF6e6 uaqU1
@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*******@aust in.rr.com> wrote in news:3amqrcF6e6 uaqU1
@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.l earn.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?Ca n 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.c om, 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******@earthl ink.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

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

Similar topics

2
6516
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 in the file ? do i have to add manual file locking, or does open()/fopen() provide file locking ? Thanks,
29
3408
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
32429
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 over the other?
8
9172
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 C can be used to perform this task. Thanks you so much
4
3656
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 *p_afile; if((p_afile = fopen("shoppinglist.txt", "r")) == NULL) { fprint("Could not open file");
27
7695
by: Jack | last post by:
What is the difference betweeb the two functions? Thanks.
4
3285
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 HTML and I try to read or open with file() or fopen(), it doesn't work, I have the following errors :
5
1563
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: fopen(http://www.somesite.com) : failed to open stream: Success in /home/etc/etc/etc/etc/test.php on line 766 Unable to open file! I cant actually figure out what the error is reffering to???
3
9670
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
9620
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.