Like you said, use a timer to call fread and close it afterwards, also why?
|
That doesn't help considering I will have to start reading from a specific line which is basically impossible.
I have alot of lines to read and it takes some time to read & put some actions on each line within one step. |
ProcessFile(filename[], interval) { new File: handle = fopen(filename, io_read); if(handle) SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); } ReadLines(File: handle, interval) { new string[128]; if(fread(handle, string)) { // do whatever SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); // continue reading } else // nothing left unread { fclose(handle); } }
https://sampwiki.blast.hk/wiki/Fseek
A more simplier way is to open the file outside the timer function and pass the file handle to read timer. Then you close the file when it is completely read (i.e fread returns 0) Doing so, you won't have to open&seek&close the file at every timer call. Pseudo code example: Код:
ProcessFile(filename[], interval) { new File: handle = fopen(filename, io_read); if(handle) SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); } ReadLines(File: handle, interval) { new string[128]; if(fread(handle, string)) { // do whatever SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); // continue reading } else // nothing left unread { fclose(handle); } } |
https://sampwiki.blast.hk/wiki/Fseek
A more simplier way is to open the file outside the timer function and pass the file handle to read timer. Then you close the file when it is completely read (i.e fread returns 0) Doing so, you won't have to open&seek&close the file at every timer call. Pseudo code example: Код:
ProcessFile(filename[], interval) { new File: handle = fopen(filename, io_read); if(handle) SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); } ReadLines(File: handle, interval) { new string[128]; if(fread(handle, string)) { // do whatever SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); // continue reading } else // nothing left unread { fclose(handle); } } |