Linux 标准I/O流学习

今天开始学习linux编程,以下是自己感觉有用的些摘要,作为学习笔记,以见证我的学习!

 包含头文件<stdio.h>
1 打开和关闭流
    FILE * fopen              (const char* path,const char * mode );
    FILE * freopen          (const  char *path,const char * mode,FILE *stream);
        将原stream所打开的文件流关闭,然后打开参数path的文件
        FILE *fp;
        fp = fopen("a.txt", "r");
        fp = freopen("b.txt", "r", fp); /* 改fp指向b.txt, 并关闭a.txt */
        fclose(fp);
    FILE * fdopen       (int filde,const char * mode);
        ???????????
     int    * fclose           (FILE * stream);
2 流的读写
   (1)读写数据块
    int fread(void *ptr, int size, int nitems, FILE *stream);
        用于接收数据的地址(ptr)
            单个元素的大小(size)
            元素个数(nitems)
            提供数据的文件指针(stream)
        返回值:成功读取的元素个数
    int fwrite(const void *ptr, int size, int nitems, FILE *stream);
   (2)读写字符
    int fgetc(FILE * stream);返回读取到的字符
    int fputc(int c,FILE * stream);
        如果失败都返回EOF
   (3)读写字符串
    char *fgets(char *s,int size,FILE * stream);成功返回缓冲区指针s,失败NULL
    int   *fputs(const char*s,FILE * stream);失败返回EOF
3 定位流
    void rewind(FILE * stream);将文件指针重新指向一个流的开头
    int fseek(FILE *stream, long offset, int fromwhere);重定位流stream为从fromwhere开始的offset处
           long ftell(FILE * stream);返回当前位置,失败-1
   
流的检测
          int feof(FILE *stream);检查是否处于文件结束位置,是返回1,否返回0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值