write ( )
原型:#include<unistd.h>
size_t write(int fd,const void *buf,size_t nbytes);
功能:把缓冲区buf 的前nbytes个字节写入与文件描述符fd关联的文件中
返回:返回实际写入的字节数,0 代表未写出数据 ;-1 调 write( )出错了 错误代码保存在 errno 里面
0:标准输入
1:标准输出
-1:标准错误
[jl@localhost test]$ gcc writee.c -o writee
[jl@localhost test]$ ./writee
here is some data
hahhahha
[jl@localhost test]$
把18改成17
[jl@localhost test]$ gcc writee.c -o writee
[jl@localhost test]$ ./writee
here is some datahahhahha
改成16
[jl@localhost test]$ gcc writee.c -o writee
[jl@localhost test]$ ./writee
here is some dathahhahha
[jl@localhost test]$
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
write(1,"here is some data\n",18);//直接写到终端了 第18个字符是\n 17个是a 哦
write(0,"hahhahha\n",9);
printf(0,"%s");
exit(0);//退出进程
}
[jl@localhost test]$ ./writee
hheh
hheh
�� 不知道哪的问题
[jl@localhost test]$
[jl@localhost test]$ ./writee
dfghkeishgkf
dfghkeishgkf
8㦿9?�|�
[jl@localhost test]$ ./writee
ertyuiopl
ertyuiopl
���9?�|�
[jl@localhost test]$ ./writee
wertyur
wertyur
�
[jl@localhost test]$ ./writee
erfhgjtnb
erfhgjtnb
d误�9?�|�
[jl@localhost test]$
[jl@localhost test]$ ./writee
rtyuhgfd 输入8个字符刚好没乱码
rtyuhgfd
[jl@localhost test]$
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
char buff[10];
int nread;
nread=read(0,buff,10);//执行后会等待输入 输入完字符回车终端会显示刚输入的字符
printf("%s\n",buff);
return 0;
}