Author Topic: How might i get the first word from a file on every line?  (Read 414 times)

function getfirst()
{
%file = new fileobject();
%file.openforread("config/server/filestuff.txt");
while(!%file.isEOF())
{
%line = %file.readline();
%name = getword(%line,0);
%file.close();
%file.delete();
//return %name;
echo(%name);
}
}

What am i doing wrong?
It doesnt seem to work

Code: [Select]
while(!%file.isEOF())
{
%firstword = getWord(%file.readLine(), 0);
echo(%firstword);
}
%file.close();
%file.delete();

You had %file.close and .delete in the while loop so it closed it on the first pass.

...


You are closing and deleting the file object inside the while loop.





You then promptly call the inverse of a nonexistant function (defaults to zero).

Well done. Enjoy your while(true) loop.

Remove while(!%file.isEOF()), why is it there?
Just call readLine() once...

Remove while(!%file.isEOF()), why is it there?
Just call readLine() once...
He wants the first word from EVERY line.

You're right, somehow all I saw was file, first and line