直接代码展示:
char* testfn()
{
int count, total = 0;
char * buffer = NULL;
int filelenth = 0;
long file_stream;
char * filename = "F:\test.txt";
if ((file_stream = fopen(filename, "r")) == NULL )
{
lr_error_message ("Cannot open %s", filename);
return NULL;
}
fseek(file_stream,0,2); //定位到文件末尾
filelenth = ftell(file_stream); //获取文件总长度
fseek(file_stream,0,0); //定位文件开头
buffer = (char *)malloc(filelenth); //动态分配内存
count = fread(buffer, sizeof(char), filelenth, file_stream); //读取文件
lr_output_message ("%d bytes read", count);
lr_output_message ("content read = %s", buffer );
if (fclose(file_stream))//关闭文件
{
lr_error_message ("Error closing file %s", filename);
}
return buffer;
}
Action()
{
char *pt = NULL;
pt = testfn();
lr_save_string(lr_eval_string(pt), "param");
lr_output_message("value of param: %s",lr_eval_string("{param}"));
free(pt); //释放内存
return 0;
}
运行结果: