系统调用 4--read

来源:互联网 发布:阿里云招聘官网首页 编辑:程序博客网 时间:2024/06/08 07:02
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>/***********************************file:read.c*author:QG*time:2015-05-10*description:***********************************/int main(){    char *file = "./123.txt";    int a = 0,read_size = 0;    char buf[10];    a = open(file,O_RDONLY);    if(a < 0)    {        printf("open file fail!\n");    }    else     {        printf("open file is success,descriptor is %d \n",a);    }    /**************************    *func:int read();    *parametre:     *return:    *function:    ****************************/    read_size = read(a,buf,9);    buf[9] = '\0';    if(read_size < 0)    {        printf("read count is %d\n",read_size);     }    else    {        printf("read count is %d\n",read_size);    }    printf("read is %s\n",buf);    return 0;    }
0 0
原创粉丝点击