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

posted @ 2005-04-13 16:35  盈盈的工作小纸条  阅读(952)  评论(0编辑  收藏  举报