Hi all,
We have 2 commands for reading scriptdata. But what is exactly the difference? With fgetarg you can read a certain argument, but what does freadln do exactly?
Hi all,
We have 2 commands for reading scriptdata. But what is exactly the difference? With fgetarg you can read a certain argument, but what does freadln do exactly?
freadln just reads the amount of args on a line and skips to the next line after (first freadln doesnt actually skip to the next line, else you wouldnt be able to get the argcount on line 1 AND read the args)
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
Ni3ls (27th October 2015)
But how to use freadln properly? And is it even that usefull?
PHP Code:
readfile(filename)
{
result = [];
fid = openfile(filename, "read");
if(fid == -1)
return undefined;
linenum = 0;
argcount = freadline(fid);
while(argcount > -1)
{
result[linenum] = [];
for(i = 0; i < argcount; i++)
result[linenum][result[linenum].size] = fgetarg(fid, i);
argcount = freadline(fid);
}
closefile(fid);
return result;
}
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
Ni3ls (27th October 2015)
So for example when I have a file like this
How can I read all those values and store them in an array?Code:1234, 1245, 1236, 234645, 131233,
PHP Code:
readthatfile()
{
f = openfile("thatfile.txt", "read");
if(f == -1)
return;
argcount = freadln(f);
if(argcount == -1) //end of file
return;
result = [];
for(i = 0; i < argcount; i++)
{
result[i] = fgetarg(f, i);
}
closefile(f);
return result;
}
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
kung foo man (28th October 2015),Ni3ls (28th October 2015)
Works perfectly!