readfile.c
来自「U/COS FS 风河为U/COS开发的文件系统.此为源码.」· C语言 代码 · 共 62 行
C
62 行
/*
**********************************************************************
* 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 + =
减小字号Ctrl + -
显示快捷键?