您现在的位置是:首页
>
C语言write write(Unix命令行程式和内建指令)详细资料大全
write U ix命令行程式和内建指令 详细资料大全 write是一个U ix命令行程式和内建指令,功能是写到一档案中,用法是i t write i t ha dle, void * uf, i t

write(Unix命令行程式和内建指令)详细资料大全
write是一个Unix命令行程式和内建指令,功能是写到一档案中,用法是int write(int handle, void *buf, int nbyte)。
基本介绍
函式名:write()功能:写到档案中函式原型:int write()所在头档案:unistd.h 程式例,Linux C,相关函式,表头档案,定义函式,函式说明,返回值,错误代码,程式例
函式名: write 功 能: 写到一档案中 用 法: int write(int handle, void *buf, int nbyte); 程式例:#include<stdlib.h>#include<unistd.h>#include<stdio.h>#include<string.h>#include<ftl.h>#include<errno.h>int main(void){int handle;char string[40];int length,res;if((handle=open("TEST.$$$",O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE))==-1){printf("Erroropeningfile.n");exit(1);}strcpy(string,"Hello,world!n");length=strlen(string);if((res=write(handle,string,length))!=length){printf("Errorwritingtothefile.n");exit(1);}printf("Wrote%dbytestothefile.n",res);close(handle);return 0;}struct xfcb{char xfcb_flag;char xfcb_resv[5];char xfcb_attr;struct fcbxfcb_fcb;}; 名称 : write 使用许可权 : 所有使用者 使用方式 : write user [ttyname] 说明 : 传讯息给其他使用者 把计 : user : 预备传讯息的使用者帐号 ttyname : 如果使用者同时有两个以上的 tty 连线,可以自行选择合适的 tty 传讯息 例子.1 : 传讯息给 Rollaend,此时 Rollaend 只有一个连线 : write Rollaend 接下来就是将讯息打上去,结束请按 ctrl+c 例子.2 :传讯息给 Rollaend,Rollaend 的连线有 pts/2,pts/3 : write Rollaend pts/2 接下来就是将讯息打上去,结束请按 ctrl+c 注意 : 若对方设定 mesg n,则此时讯息将无法传给对方Linux C
write(将数据写入已打开的档案内)相关函式
open,read,ftl,close,lseek,sync,fsync,fwrite表头档案
#include<unistd.h>定义函式
ssize_t write (int fd,const void * buf,size_t count);函式说明
write()会把指针buf所指的记忆体写入count个位元组到参数fd所指的档案内。当然,档案读写位置也会随之移动。返回值
如果顺利write()会返回实际写入的位元组数。当有错误发生时则返回-1,错误代码存入errno中。错误代码
EINTR 此调用被信号所中断。 EAGAIN 当使用不可阻断I/O 时(O_NONBLOCK),若无数据可读取则返回此值。 EBADF 参数fd非有效的档案描述词,或该档案已关闭。 很赞哦! (1059)