关于read(...)和write(...)的问题.

ljf1107 2001-08-26 05:11:29
请大侠给出UNIX下的read和write的参数列表.
并请解释write(1,buff/*一个指向char型的指针*/,0)是什么意思,谢谢.
并请教lseek的用法.必给分.谢谢.
...全文
73 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fsb_12345 2001-08-27
  • 打赏
  • 举报
回复
#include <sys\stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

int main(void)
{
int handle;
char msg[] = "This is a test";
char ch;

/* create a file */
handle = open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE);

/* write some data to the file */
write(handle, msg, strlen(msg));

/* seek to the beginning of the file */
lseek(handle, 0L, SEEK_SET);

/* reads chars from the file until we hit EOF */
do
{
read(handle, &ch, 1);
printf("%c", ch);
} while (!eof(handle));

close(handle);
return 0;
}
fsb_12345 2001-08-27
  • 打赏
  • 举报
回复
int read(int handle,void *buf,int nbyte)
从文件号为handle的文件中读nbyte个字符存入buf中

int write(int handle,void *buf,int nbyte)
将buf中的nbyte个字符写入文件号为handle的文件中

long lseek(int handle,long offset,int fromwhere)
本函数将文件号为handle的文件的指针移到fromwhere后的第offset个字节处.
SEEK_SET文件开关 SEEK_CUR当前位置 SEEK_END文件尾
leechie 2001-08-26
  • 打赏
  • 举报
回复
1:stdout>>>>标准输出

int read(int fd,char *buffer,int size);
int write(int fd,char *buffer,int size);

off_f lseek(int fd,off_t offset,int whence);
whence=0,1,2>>>0:文件头+offset;1:文件当前+offset;2:文件尾+offset

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧