SA-MP Forums Archive
Explain "fread"? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Explain "fread"? (/showthread.php?tid=166168)



Explain "fread"? - Ash. - 07.08.2010

Hi all,
Ive just begun on a house system that i will probably be releasing, if it all goes to plan, however i have come accross my first problem.

pawn Код:
fread
I dont understand it. I know about its handle, but lets say i have multiple strings in 1 file, how do i pick one of them? Can somebody explain fread, how to get certain strings (possibly on certain lines) and how it works?

Thanks
Ash


Re: Explain "fread"? - RyDeR` - 07.08.2010

fread:

file read.

Reads a file per line.


Re: Explain "fread"? - Ash. - 07.08.2010

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
fread:

file read.

Reads a file per line.
So to just read line 23 (for example) i would do?


Re: Explain "fread"? - RyDeR` - 07.08.2010

Here, I've just written this function for you to make it easier (put it at the end of the script (to make it easy)):
pawn Код:
freadLine(File: handle, line)
{
    new
        string[128]
    ;
    for(new x; x != line; x++)
    {
        fread(handle, string);
    }
    return string;
}
Example/Usage:
This function returns the info on the line you defined.

Example:
pawn Код:
new
    File: file = fopen("test.txt", io_read)
;
printf("%s", freadLine(file, 23));
This will give us all info which is on line 23. Just change the line to get other info.

Other questions about this let it know.