Racemaniac
Scorched GP programmer
i made some code to read a txt file, line per line and storing every line in a seperate string
have a look:
*edit* little correction made ^^
just a basic example, but it works
can be useful
the current program will show the first 10 lines it finds
and every line has to be ended with a return (or the program won't find it , so if it doesn't see the last line, you know why )
this is tested with txt's made with notepad
have a look:
*edit* little correction made ^^
Code:
program textreader;
global
power[4]=1,256,256*256,256*256*256;
textfile[1000];//we'll read up to 4000 chars
string line[100];//up to 100 lines, should be enough?
private
i;
begin
readfile("newdoc.txt");
for(i=0;i<10;i++)
write_string(0,160,5+i*10,4,&line[i]);
end
loop
frame;
end
end;
function readfile(string filename)
private
string chars[100];//up to 98 chars on a line (last two are for end of line)
lasttwo[2];
lastj;
j;
i;
begin
load(filename,textfile);
while(j<4000)
lasttwo[0]= (textfile[j/4]/power[j%4])%256;
chars[j-lastj]=chr(lasttwo[0]);
j++;
lasttwo[1]= (textfile[j/4]/power[j%4])%256;
chars[j-lastj]=chr(lasttwo[1]);
while((lasttwo[1]!=10 or lasttwo[0]!=13)and j<4000 and j-lastj<100);
j++;
lasttwo[0]=lasttwo[1];
lasttwo[1]= (textfile[j/4]/power[j%4])%256;
chars[j-lastj]=chr(lasttwo[1]);
end;
j++;
if(j-lastj==101);
return;
end
line[i++]=join("",&chars,j-lastj-2);
lastj=j;
end
return;
end;
can be useful
the current program will show the first 10 lines it finds
and every line has to be ended with a return (or the program won't find it , so if it doesn't see the last line, you know why )
this is tested with txt's made with notepad