读和写 [英] read and write

查看:65
本文介绍了读和写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

任何人都可以解释一下如何在C中使用read()write()函数。


以及如何读取文件从磁盘上显示并使用

onlu read(),write()函数??????

解决方案

在文章< 11 ********************** @ g37g2000prf.googlegroups .com> ;,

asit dhal< pe ******** @ gmail.comwrote:


> hello friends,
任何人都可以解释我怎么用read()write()函数在C.



通过使用stdio输入和输出函数;在一个操作系统上,它使得使用read()和write(),标准库将几乎

绝对称它们为实际输入和输出。


>以及如何从磁盘读取文件并使用
onlu read(),write()函数在监视器上显示它??????



使用超出comp.lang.c范围的系统特定细节。

dave

-

Dave Vandervies dj******@csclub.uwaterloo .ca

我_am_一致 - 如果其中一个指针指导作者来这里并且要求征求意见,那么他们就会被咀嚼出来很糟糕。

- 在comp.lang.c中的理查德博斯


" asit dhal" < pe ******** @ gmail.comschrieb im Newsbeitrag

新闻:11 ********************** @ g37g2000prf.googlegr oups.com ...


你好朋友,

任何人都可以解释我如何使用read()write()函数在C.



在C89或C99中没有这样的函数。虽然它们在POSIX中,所以

comp.unix.programmer中的guye会知道它们


以及如何读取文件从磁盘上显示它并使用

onlu read(),write()函数??????



不,不行。此外,至少还需要open(),close()。

标准C没有磁盘和监视器的概念。

最接近的东西监视器可能是stdout ...并且进程得到

它是理所当然的。


伪代码(并且没有错误处理):


file = open(filename,read)

do

bytesread = read(file,buffer,sizeof buffer)

写(stdout_fileno,buffer,bytesread)

直到文件命中EOF

关闭(文件)


实现剩下的运动(作业?)到OP ...


再见,Jojo


asit dhal写道:
< blockquote class =post_quotes>
你好朋友,

任何人都可以解释我如何在C中使用read()write()函数。



在C中没有函数read()和write()。有各种

函数,这些函数具有不同实现和platfo的名称rms,

最常见的是那些naems的POSIX功能。要使用

,你必须使用适当的实现并包含

非标准头文件,以非标准方式识别流。


以及如何从磁盘读取文件并使用

onlu read(),write()函数在显示器上显示它???????



在C中,可以读取输入流,用fopen()打开,用

fread()等读取,然后写它是一个带有fwrite()

的输出流。


即使在支持POSIX read()和write()的实现中也是如此b $ b功能你要求的是不可能的。除此之外,你必须以某种方式打开你想要读取的文件,除非在命令

line上重定向为stdin流,这需要读取以外的函数( )

并写()。


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 ??????

解决方案

In article <11**********************@g37g2000prf.googlegroups .com>,
asit dhal <pe********@gmail.comwrote:

>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 dj******@csclub.uwaterloo.ca
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


"asit dhal" <pe********@gmail.comschrieb im Newsbeitrag
news:11**********************@g37g2000prf.googlegr 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


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().


这篇关于读和写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆