File_EOF()

Parent Previous Next

File_EOF(), Bit


Return Value:

0: No, the end of the file has not been reached.

1: Yes, the end of the file has been reached.


Check if End of File (EOF) is Reached


File_EOF is a variable used to check if the end of a file (EOF) has been reached while reading a file. When a file is being read, it is important to detect when there is no more data to read, to avoid errors or infinite loops.


Example:

File_EOF()


Prevent Blocking Loop with EOF:

File_EOF() is useful to prevent situations where a program might get stuck in an infinite loop if the end of the file is not handled correctly. By checking File_EOF(), you can safely terminate file reading when all content has been processed.


When to Use:

• During file reading: Whenever you're reading a file, you can use File_EOF() to ensure that you don't attempt to read beyond the end of the file.

• Prevent blocking behavior: Checking EOF prevents your code from getting stuck in a read loop after the file ends.


Notes:

• Ensure that you call File_Open() before using File_EOF(), as this variable only applies to files that are open for reading.

File_EOF() helps avoid errors like Read/Write error (RWError) when you try to read past the file’s content.


TftSetUp(0)                                                                                 'Set screen

TftResetScreen(BLACK)                                                                       'Reset screen

TftSetSndFont(0,0)                                                                          'Set Font0

While File_Init() <> cErrOK : Wend                                                          'Initialize SD Card

TftPrintSndString("Sd Initialization OK",1,0,0,1,GREEN,BLACK,0)                             'Confirm Initialize SD Card

While File_Open("Open.txt") <> cErrOK : Wend                                                'Open file Open.txt to edit data

TftPrintSndString("Open Open.txt OK",1,0,2,1,GREEN,BLACK,0)                                 'Confirm Open.txt is open 

bCounter = 0                                                                                'Print position counter

Do

    TftPrintSndChar(File_ReadByte(),1,bCounter,3,1,GREEN,BLACK,0)                           'Print data as text

    If File_EOF() = 1 Then Break                                                            'Loop till end of file

    Inc bCounter  

Loop             

File_Close()                                                                                'close file

TftPrintSndString("Close Open.txt OK",1,0,4,1,GREEN,BLACK,0)                                'Confirm close file






Created with the Personal Edition of HelpNDoc: Effortlessly Create Encrypted, Password-Protected PDFs