zoukankan      html  css  js  c++  java
  • Linux练习(read读取)

    #include <unistd.h>
    #include <stdlib.h>
    
    int main()
    {
            char buffer[128];
            int nread;
    
            nread=read(0,buffer,128);
            if(nread==-1)
                    write(2,"A read error has occurred\n",26);
            if((write(1,buffer,nread))!=nread)
                    write(2,"A write error has occurred\n",27);
            exit(0);
    }

    函数原型:

    #include <unistd.h>

    size_t read(int fildes,const void *buf,size_t nbytes);

    read()参数一:同write()

       参数二:读取的数据

       参数三:读取的数据的大小

    返回:

    正常情况下返回读取的数据的大小,即nbytes

    返回0表示没有读入任何数据,可能达到了文件尾

    返回-1表示出错了

  • 相关阅读:
    数据库中Schema(模式)概念的理解
    git错误处理
    mysql存储过程
    bunyan
    golang 小问题
    操作系统
    数据库优化
    内存控制
    MySQL优化2
    mysql优化1
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2667726.html
Copyright © 2011-2022 走看看