Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > read and write

Reply
Thread Tools

read and write

 
 
asit dhal
Guest
Posts: n/a
 
      05-29-2007
hello friends,
can anyone explain me how to use read() write() function in C.

and also how to read a file from disk and show it on the monitor using
onlu read(), write() function ??????

 
Reply With Quote
 
 
 
 
Dave Vandervies
Guest
Posts: n/a
 
      05-29-2007
In article <(E-Mail Removed) .com>,
asit dhal <(E-Mail Removed)> wrote:
>hello friends,
>can anyone explain me how to use read() write() function in C.


By using the stdio input and output functions; on an OS where it makes
sense to use read() and write(), the standard library will almost
definitely call them to do the actual input and output.


>and also how to read a file from disk and show it on the monitor using
>onlu read(), write() function ??????


By using system-specific details that are beyond the scope of comp.lang.c.


dave

--
Dave Vandervies http://www.velocityreviews.com/forums/(E-Mail Removed)
I _am_ consistent - if one of those other pointer guide writers came
here and asked for comments, they'd get chewed out just as badly.
--Richard Bos in comp.lang.c
 
Reply With Quote
 
 
 
 
Joachim Schmitz
Guest
Posts: n/a
 
      05-29-2007
"asit dhal" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) oups.com...
> hello friends,
> can anyone explain me how to use read() write() function in C.

No such functions in C89 or C99. They are in POSIX though, so the guye in
comp.unix.programmer would know about them

> and also how to read a file from disk and show it on the monitor using
> onlu read(), write() function ??????

No, won't work. At least open() would be needed in addition, close() too.
And standard C doesn't have the notion of disk nor monitor.
The closest thing to monitor would probably be stdout... and a process gets
it for granted.

Pseudo code (and without error handling):

file = open(filename, read)
do
bytesread=read(file, buffer, sizeof buffer)
write(stdout_fileno, buffer, bytesread)
until file hits EOF
close (file)

Implementation left as an exercise (homework?) to the OP...

Bye, Jojo


 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      05-29-2007
asit dhal wrote:
> hello friends,
> can anyone explain me how to use read() write() function in C.


There are no functions read() and write() in C. There are various
functions with those names for different implementations and platforms,
the most common ones being the POSIX functions of those naems. To use
them you must be using an appropriate implementation and include
non-standard headers, identifying streams in a non-standard way.

> and also how to read a file from disk and show it on the monitor using
> onlu read(), write() function ??????


In C one can read an input stream, opened with fopen(), read it with
fread() among others, and write it to an output stream with fwrite()
among otheres.

Even in implementations supporting the POSIX read() and write()
functions what you ask for is impossible. Among other things, you must
somehow open the file you want to read, unless redirected on the command
line as the stdin stream, which requires a function other than read()
and write().


 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      05-30-2007
In article <(E-Mail Removed). com>,
Darko <(E-Mail Removed)> wrote:
>On May 29, 10:52 pm, CBFalconer <(E-Mail Removed)> wrote:


>> There is no read nor write function in C. Look up such things as
>> fopen, fclose, fread, fwrite.


>Let be honest, then, there are no functions fopen, fclose, fread,
>fwrite neither in C.


ISO 9899 disagrees with you.


dave

--
Dave Vandervies (E-Mail Removed)
>Just promise to never show up at a BOFHBOF in Spandex and it's all moot.

Being Canadian, my favourite specialty fabric is Thinsulate.
--Graham Reed and Anthony de Boer in the scary devil monastery
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      05-30-2007
In article <(E-Mail Removed). com>,
Darko <(E-Mail Removed)> wrote:

>Let be honest, then, there are no functions fopen, fclose, fread,
>fwrite neither in C. C is just a "shell", that contains only syntax.
>open, close, write and read are functions supported by the O.S. as
>part of drivers interface, and stdio functions use them implicitly,
>cause there's no way to write/read, open/close any device without
>these functions - they are embedded in the drivers directly, and given
>by the O.S. through various interfaces (e.g. a C library)


>Ask about these on comp.unix.programmer.


And if one is not using Unix?

You are making an assertion about how *all* systems work. That
assertion is not true for a number of systems. For example, there
are systems which have no drivers interface at all.

--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      05-30-2007
Darko said:

> On May 29, 10:52 pm, CBFalconer <(E-Mail Removed)> wrote:
>> asit dhal wrote:
>>
>> > can anyone explain me how to use read() write() function in C.
>> > and also how to read a file from disk and show it on the monitor
>> > using onlu read(), write() function ??????

>>
>> There is no read nor write function in C. Look up such things as
>> fopen, fclose, fread, fwrite.

>
> Let be honest, then, there are no functions fopen, fclose, fread,
> fwrite neither in C.


Should I believe you, or the ISO C Standard? Hmmm. Think think think...

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-30-2007
Darko <(E-Mail Removed)> writes:
> On May 29, 10:52 pm, CBFalconer <(E-Mail Removed)> wrote:
>> asit dhal wrote:
>>
>> > can anyone explain me how to use read() write() function in C.
>> > and also how to read a file from disk and show it on the monitor
>> > using onlu read(), write() function ??????

>>
>> There is no read nor write function in C. Look up such things as
>> fopen, fclose, fread, fwrite.

[signature snipped]
>
> Let be honest, then, there are no functions fopen, fclose, fread,
> fwrite neither in C. C is just a "shell", that contains only syntax.


Let's be correct as well as honest.

The C language is defined by the ISO C standard (either the 1990 or
the 1999 version; the differences are not relevant in this case).
That standard defines the fopen, fclose, fread, and fwrite functions
in section 7, along with a plethora of other functions. (Most of
these are required only for hosted implementations, but that's beside
the point.)

These functions are part of the C language, just as much as the syntax
*and semantics* defined in section 6.

(A minor quibble: the standard's section 6, describing syntax and
semantics, is titled "Language", and section 7 is titled "Library",
but they're both part of the C standard, and part of C.)

> open, close, write and read are functions supported by the O.S. as
> part of drivers interface, and stdio functions use them implicitly,
> cause there's no way to write/read, open/close any device without
> these functions - they are embedded in the drivers directly, and given
> by the O.S. through various interfaces (e.g. a C library)


That depends on the operating system. On some C implementations, the
fopen, fclose etc. functions might be implemented using some other
lower-level functions; the OS might not even have functions called
"open" and "close", or it may have functions with those names that do
something entirely different than what the POSIX-specified functions
do. On yet other C implementations, fopen and fclose might even be
implemented by directly acessing the hardware.

> Ask about these on comp.unix.programmer.


.... where you're more likely to get accurate answers.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      05-30-2007
Darko wrote:
Usenet account fromhttp://www.teranews.com
>
> Let be honest, then, there are no functions fopen, fclose, fread,
> fwrite neither in C.


Let us be honest, then. The above is just plain crap. If "Darko" is a
student, he should learn better. If he claims to be a programmer, he
should be fired.

> C is just a "shell", that contains only syntax.


Let us be honest, then. The above either is meaningless or is pure crap.
 
Reply With Quote
 
Chris Torek
Guest
Posts: n/a
 
      05-30-2007
In article <(E-Mail Removed) om>
Darko <(E-Mail Removed)> wrote:
>... These quotes also clearly distinguish the language from the library.


What I think you have missed here is that the C standards (C89 and
C99 both) split the world into two: "hosted implementations" and
"freestanding". A "hosted" implementation is *required* to have
the full Standard C Library, and -- though this is not "required",
merely "allowed" -- a hosted compiler can assume that a call to,
e.g., printf() or sqrt() does only what the C Standard says it
does, and *remove the call* from a compiled program, replacing it
with something that suffices given the actual arguments.

Some compilers do in fact do this. In an extreme case,

printf("%f\n", sqrt(4.0));

could compile to the same machine code as:

puts("2.000000");

(in practice this particular line usually still calls printf(),
but on some compilers, passes 2.0 directly, without first calling
sqrt(); some other printf() calls are turned into puts() calls
though -- and note that the newline is removed from the string when
printf() is changed into puts()).

>It seems that it all comes down to the question what "C" is ...


It is what the C Standard says it is, provided all parties agree to
the C Standard (which then brings up the case of "*which* C standard"
of course ):

>- the library, the library and the language, or the language.


Going by the C Standard (either C89 or C99), it is never just "the
library"; it is usually "the library and language combined", but
for "freestanding" systems, it is "the language, plus at least a
few parts of the library as listed, plus anything the freestanding
system includes anyway". (See the Standard's section on conformance.)

>So, the standard is extensible, because it contains libraries aside
>from the language itself. Let's make an example - can some of the
>following headers (mentioned in the document, as part of the standard
>library) be considered a part of "C":
><signal.h> <setjmp.h>


<signal.h> is not required in a freestanding implementation, but
is required (along with its corresponding functions) in any hosted
implementation. Note that the functions can be quite trivial,
e.g., signal() can simply return SIG_ERR much of the time.

<setjmp.h> is similar, except that setjmp and longjmp cannot be
implemented trivially (a correct call to longjmp() must always
perform the requested "go to").

On the other hand, for instance, <stddef.h> is always required,
even in freestanding implementations.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
 
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
I need to write Simple JAVA program to read and write from USB serialto use it with Arduino sahm Java 4 10-15-2012 06:24 PM
want to replace a read only cd transport with read / write transport larya Computer Support 7 09-11-2006 10:21 PM
how to encrypt a C data and write a bin file and read a bin at run time and decrypt C data sweety C Programming 9 02-07-2006 05:28 PM
How to know if a method is read-write or read-only Trans Ruby 3 12-21-2005 12:21 AM
Re: How to change Read Only Constraint to Read-Write Isaac VHDL 0 07-10-2003 01:43 PM



Advertisments