TA的每日心情 | 奋斗 2015-6-25 18:04 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
LR自带的函数说明
long fopen ( const char *filename, const char *access_mode );
filename:The name of the file to open.
access_mode:The type of access mode: r, w, a or r+, w+, a+, where the "+" sign indicates that the file must already exist.
Action() {
int count, total = 0;
char buffer[1000];
long file_stream;
char *filename = "c:\\readme.txt";
/* Open the file with read access */
if ((file_stream = fopen(filename, "r")) == NULL ) {
lr_error_message("Cannot open %s", filename);
return -1;
}
/* Read until end of file */
while (!feof(file_stream)) {
/* Read 1000 bytes while maintaining a running count */
count = fread(buffer, sizeof(char), 1000, file_stream);
lr_output_message("%3d read", count);
/* Check for file I/O errors */
if (ferror(file_stream)) {
lr_output_message("Error reading file %s", filename);
break;
}
total += count; /* add up actual bytes read */
}
/* Display final total */
lr_output_message("Total number of bytes read = %d", total );
/* Close the file stream */
if (fclose(file_stream))
lr_error_message("Error closing file %s", filename);
return 0;
}
Output:
Action.c(19): 1000 bytes read
Action.c(19): 1000 bytes read
...
Action.c(19): 1000 bytes read
Action.c(20): 977 read
Action.c(34): Total number of bytes read = 69977 |
|