标准IO(fopen-fclose-fread-fwrite-fseek-ftell-rewind)

一、标准IO和系统IO的使用场景
系统IO:适用于打开设备文件(硬件文件) LCD、 触摸屏(效率比较高) ;可以打开硬件文件也可以打开普通文件
标准IO:适用于打开普通文件 ,比如txt png bmp jpg;无法去打开硬件设备文件

二、标准IO
系统IO:open read write close lseek 
标准IO:fopen fread fwrite fclose fseek(标准库里面的函数  man 3)

 

三、标准IO的API (access prosess interface)
1.fopen 打开文件
       #include <stdio.h>

       FILE *fopen(const char *path, const char *mode);
参数:
    path:文件路径名
    mode:权限
           r      Open text file for reading.  The stream  is  positioned  at  the
                      beginning of the file. 
    只读 光标定位在文件头
           r+     Open  for  reading and writing.  The stream is positioned at the
                  beginning of the file.
    可读可写 光标定位在文件头
           w      Truncate file to zero length or create text  file  for  writing.
                  The stream is positioned at the beginning of the file.
    只写,如果文件存在就清空,如果文件不存在就创建,光标定位在文件头
           w+     Open  for  reading  and writing.  The file is created if it does
                  not exist, otherwise it is truncated.  The stream is  positioned
                  at the beginning of the file.
    可读可写,如果文件存在就清空,如果文件不存在就创建,光标定位在文件头
           a      Open  for  appending (writing at end of file).  The file is cre‐
                  ated if it does not exist.  The stream is positioned at the  end
                  of the file.
    追加(写在文件尾),如果文件不存在就创建,光标定位在文件尾
           a+     Open  for  reading  and appending (writing at end of file).  The
                  file is created if it does not exist.  The initial file position
                  for  reading  is  at  the  beginning  of the file, but output is
                  always appended to the end of the file.
    可读可追加,如果文件不存在就创建,读文件光标定位在文件头,追加文件光标定位在文件尾。
返回值:
    成功:文件指针 FILE *
    失败:NULL

总结:
带有‘r’:可读或者可读可写,需要手动创建
带有‘w’:可写或者可读可写,如果没有自动创建
带有'a' :   具有特殊功能的写(追加写),如果没有自动创建
mode变量的赋值要使用字符串,不是字符 。如"r" "r+" "w" "w+"

<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值