Prueba tambien este codigo de Racemaniac:
i made some code to read a txt file, line per line and storing every line in a seperate string
have a look:
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 :P )
this is tested with txt's made with notepad
Código:
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;
Es bastante util para leer textos desde un .txt externo. Para acabar las frases usa Return o no lo entendera. Puede ser una solucion para tu problema de controlar el largo de las frases.
Si no recuerdo mal, tengo un codigo mio viejo de un juego tipo Quiz donde mezcle este programa para leer las preguntas desde un .txt y las representaba en pantalla mediante el Qwrite de Moogle/Quiest.
A ver si lo recupero porque la verdad es que era gracioso.
Saludos!
Marcadores