zoukankan      html  css  js  c++  java
  • lr中读写文件操作代码(原创)

    1.lr中支持的读写函数有:

    Function Name
    Description
    Closes a file.
    Check
    s if the end of file has occurred on a stream.
    Checks if any error has occurred during file I/0.
    Gets a character from a stream.
    Reads a string from a file.
    Opens a file for buffered I/0.
    Writes formatted output to a file.
    Writes a character to a stream.
    Reads unformatted data from a stream into a buffer.
    Reads formatted input from a stream.
    Sets the current position in a file to a new location.
    Write unformatted data from a buffer to a stream.
    Rewinds a file.
    Writes formatted output to a string.
    Reads formatted input from a string.

    2. 以下的例子是打开文件并追加写入该文件

    char *pr;
    char *filename= "e://log.txt";
    long file;
    char *p;
    if ((file = fopen(filename, "at")) == NULL ) {

              lr_error_message("Cannot open %s", filename);

              return -1;
         }

     p = lr_eval_string("{pr}");

     
     while ((*p != NULL) && fputc(*(p++), file) != -1); 
     
     fputc("\n",file);

     fclose(file);

    3.补充c函数知识:

    文件使用方式        意 义
    “rt”      只读打开一个文本文件,只允许读数据
    “wt”      只写打开或建立一个文本文件,只允许写数据
    “at”      追加打开一个文本文件,并在文件末尾写数据
    “rb”      只读打开一个二进制文件,只允许读数据
    “wb”       只写打开或建立一个二进制文件,只允许写数据
    “ab”       追加打开一个二进制文件,并在文件末尾写数据
    “rt+”      读写打开一个文本文件,允许读和写
    “wt+”      读写打开或建立一个文本文件,允许读写
    “at+”      读写打开一个文本文件,允许读,或在文件末追加数 据
    “rb+”      读写打开一个二进制文件,允许读和写
    “wb+”      读写打开或建立一个二进制文件,允许读和写
    “ab+”      读写打开一个二进制文件,允许读,或在文件末追加数据

  • 相关阅读:
    cesium学习——cesium中的坐标
    webService框架CXF的简单使用
    使用cesium中的scene.open中遇到的几个问题
    通过Spring读取properties配置文件
    常用的Ant风格书写
    oracle小知识点
    虚拟机centos7系统下安装hadoop ha和yarn ha(详细)
    java 注解
    Guava Immutable 不可变集合
    Guava BiMap
  • 原文地址:https://www.cnblogs.com/morebetter/p/136910.html
Copyright © 2011-2022 走看看