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+”      读写打开一个二进制文件,允许读,或在文件末追加数据

  • 相关阅读:
    hdu 4747 Mex( 线段树? 不,区间处理就行(dp?))
    hdu 5692 Snacks(dfs时间戳+线段树)
    hdu 1864 最大报销额(背包)
    hdu 2955 Robberies(概率背包)
    hdu 4055 Number String (基础dp)
    4516: [Sdoi2016]生成魔咒
    2555: SubString
    后缀自动机·小记
    CF 1114 E. Arithmetic Progression
    CF 1114 D. Flood Fill
  • 原文地址:https://www.cnblogs.com/morebetter/p/136910.html
Copyright © 2011-2022 走看看