unix/Linux 低级IO函数的用法read && write
来源:互联网 发布:淘宝店铺宝贝描述图片 编辑:程序博客网 时间:2024/05/18 06:36
unix/Linux 低级IO函数的用法read && write
简单的读一个文件:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
int fd = 0;
int pid = 0;
char buffer[20] = {'/0'};
char *read_buffer[20] = {'/0'};
//fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);
fd = open("/dev/hello",O_RDONLY ); //| O_NONBLOCK);
printf("fd=%d/n",fd);
if(fd < 0) {
perror("/dev/hello");
return -1;
}
read(fd,read_buffer,sizeof(read_buffer)-1);
printf("read_buffer=%s/n",read_buffer);
close(fd);
return 0;
}
---
下面这个就是简单的写一个文件 ,
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
int fd = 0;
int pid = 0;
char buffer[20] = {'/0'};
char write_buffer[20] = {'/0'};
strcpy(write_buffer,"zhanglinbao");
fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);
//fd = open("/dev/hello",O_RDONLY);
printf("fd=%d/n",fd);
if(fd < 0) {
perror("/dev/hello");
return -1;
}
write(fd,write_buffer,sizeof(write_buffer)-1);
close(fd);
return 0;
}
简单的读一个文件:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
int fd = 0;
int pid = 0;
char buffer[20] = {'/0'};
char *read_buffer[20] = {'/0'};
//fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);
fd = open("/dev/hello",O_RDONLY ); //| O_NONBLOCK);
printf("fd=%d/n",fd);
if(fd < 0) {
perror("/dev/hello");
return -1;
}
read(fd,read_buffer,sizeof(read_buffer)-1);
printf("read_buffer=%s/n",read_buffer);
close(fd);
return 0;
}
---
下面这个就是简单的写一个文件 ,
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc,char **argv)
{
int fd = 0;
int pid = 0;
char buffer[20] = {'/0'};
char write_buffer[20] = {'/0'};
strcpy(write_buffer,"zhanglinbao");
fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC);
//fd = open("/dev/hello",O_RDONLY);
printf("fd=%d/n",fd);
if(fd < 0) {
perror("/dev/hello");
return -1;
}
write(fd,write_buffer,sizeof(write_buffer)-1);
close(fd);
return 0;
}
- unix/Linux 低级IO函数的用法read && write
- unix/Linux 低级IO函数的用法
- Unix/Linux中的read和write函数
- Unix/Linux中的read和write函数
- Unix/Linux中的read和write函数
- read, write 函数用法
- C程序设计语言- UNIX系统接口-7.1----文件描述符、低级IO(read、write)、随机访问、(open、creat、close、unlink)
- linux c中write、read的用法
- Linux 文件IO函数(open/close/read/write/lseek)
- Linux -C 的read 和 write函数
- Linux -C 的read 和 write函数
- Linux下的read,write函数
- read和write函数用法
- 基本IO函数的使用(open,write,read)
- 基本IO函数的使用(open,write,read)
- 基本IO函数的使用(open,write,read)
- 低级IO - read
- Linux&C open creat read write lseek 函数用法总结
- CString源码
- C语言宏定义技巧
- SQLSERVER2005视图
- C#实现数据结构中链表示例
- 我的 博客 主页
- unix/Linux 低级IO函数的用法read && write
- 如何编写 Windows Mobile Smartphone 录音程序
- js技巧收集(200多个)
- javascript Web页面内容导出到Word、Excel
- PMI推出新认证:PgMP 项目集管理
- 强类型数据集对象(引用)
- gb2312unicode字符转换
- 考查嵌入式C开发人员的最好的0x10道题
- Database Header Page for Jet 3.x