[File]: Reading all lines? - 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)
+--- Thread: [File]: Reading all lines? (
/showthread.php?tid=540902)
[File]: Reading all lines? -
uZ1 - 08.10.2014
Hi, I've just a simple question for a simple little thing. Is it possible to read and print all lines from a file?
I use currently DINI, it would be really nice if someone give an example...
Re: [File]: Reading all lines? -
Quickie - 08.10.2014
i suggest u use y_ini cuz it can read all lines of files at once and much faster than dini
https://sampforum.blast.hk/showthread.php?tid=175565
Re: [File]: Reading all lines? -
(SF)Noobanatior - 08.10.2014
if you look in dini.inc there is lots of examples of how to read a file or use file function
im a but rusty with it but i gutted dini_get to make this quickly
should print eack line of the file to the console (untested)
pawn Код:
public printfile(filename[]){
new File:fohnd;
new tmpres[MAX_STRING];
fohnd=fopen(filename,io_read);//open file
if (!fohnd) return 0; //end if dosent exist
while (fread(fohnd,tmpres)) { //read each line
print(tmpres); //print line
}
fclose(fohnd);//close file
return 1;
}
hope that helps
Re: [File]: Reading all lines? -
YanLanger - 08.10.2014
What do you mean?
Re: [File]: Reading all lines? -
uZ1 - 08.10.2014
Quote:
Originally Posted by (SF)Noobanatior
if you look in dini.inc there is lots of examples of how to read a file or use file function
im a but rusty with it but i gutted dini_get to make this quickly
should print eack line of the file to the console (untested)
pawn Код:
public printfile(filename[]){ new File:fohnd; new tmpres[MAX_STRING]; fohnd=fopen(filename,io_read);//open file if (!fohnd) return 0; //end if dosent exist while (fread(fohnd,tmpres)) { //read each line print(tmpres); //print line } fclose(fohnd);//close file return 1; }
hope that helps
|
This helped me alot, thank you!