📄 readfile.c
字号:
/*
**********************************************************************
* Micrium, Inc.
* 949 Crestview Circle
* Weston, FL 33327-1848
*
* uC/FS
*
* (c) Copyright 2001 - 2003, Micrium, Inc.
* All rights reserved.
*
***********************************************************************
----------------------------------------------------------------------
File : ReadFile.c
Purpose : Sample program demonstrating reading
---------------------------END-OF-HEADER------------------------------
*/
#include "fs_api.h"
#include <string.h>
#include <stdio.h>
/*********************************************************************
*
* MainTask
*/
void MainTask(void);
void MainTask(void) {
FS_FILE * pFile;
char acBuffer[100];
char acLog[100];
int Count;
int Total;
FS_I16 Error;
Total = 0;
pFile = FS_FOpen("default.txt", "r");
if (pFile == NULL) {
FS_X_ErrorOut("Could not open file.");
}
/* Cycle until end of file reached: */
while (!FS_FEof(pFile)) {
Count = FS_Read(pFile, &acBuffer[0], sizeof(acBuffer));
Error = FS_FError(pFile);
if (Error) {
sprintf(acLog, "Could not read from file:\nReason = %s", FS_ErrorNo2Text(Error));
FS_X_ErrorOut(acLog);
break;
}
/* Total up actual bytes read */
Total += Count;
}
sprintf(acLog, "Number of read bytes = %d\n", Total);
FS_X_Log(acLog);
FS_FClose(pFile);
}
/*************************** End of file ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -