2013年4月1日
摘要: Linux系统中,文件和设备都被看作是数据流。要对流访问,需要stdio库提供的函数和文件指针FILE来实现。当程序执行时,有3个流回自动打开,分别是标准输入(stdin)、标准输出(stdout)、标准错误输出(stderr),结束时他们也会自动被关闭。函数fopen 打开一个文件FILE * fopen(const char * path,const char * mode);返回值:文件顺利打开后,指向该流的文件指针就会被返回。如果文件打开失败则返回NULL,并把错误代码存在errno 中。 一般而言,打开文件后会作一些文件读取或写入的动作,若打开文件失败,接下来的读写动作也无法顺利进行 阅读全文
posted @ 2013-04-01 21:49 阿逸 阅读(353) 评论(0) 推荐(0) 编辑
摘要: write(将数据写入已打开的文件内)ssize_twrite (int fd,const void * buf,size_t count);write()会把参数buf所指的内存写入count个字节到参数fd所指的文件内。当然,文件读写位置也会随之移动如果顺利write()会返回实际写入的字节数。当有错误发生时则返回-1,错误代码存入errno中。open(打开文件)int open( const char * pathname,int flags,mode_t mode);参数pathname 指向欲打开的文件路径字符串。下列是参数flags 所能使用的标志位:O_RDONLY 以只读方式 阅读全文
posted @ 2013-04-01 10:51 阿逸 阅读(680) 评论(0) 推荐(0) 编辑
摘要: #include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <signal.h>#include <stdarg.h>#include <fcntl.h>void parent(char *argv[]);void child(char *argv[]);int write_buffer(int f 阅读全文
posted @ 2013-04-01 09:51 阿逸 阅读(191) 评论(2) 推荐(0) 编辑