Helpful Information
 
 
Category: Other Programming Languages
Pascal string problem

I have made a program that opens files. Nothin' spectacular. The problem is that if the text is more then 255 characters long, the rest of the text isn't read. So I want it to open up a new string and write the rest in that string, but I dont know how. This is how far I've gotten.


program bootstat2; {™ppnar bootstat.dat}
uses
crt;
var
s, t, u : string;
f, w, q : text;
a, L : integer;
begin
clrscr;
write('Skriv in filnamnet:');
readln(t);
assign(f, t);
assign(w, 'C:logg.txt');
assign(q, 'C:logg2.txt');
rewrite(q);
reset(f);
rewrite(w);
readln(f,s);
L := length(s);
writeln(s);
writeln(w,s);
for a := 1 to L do begin
readln(f,s);
writeln(s);
writeln(w,s);
end;
if L+1 > 255 then begin
for a := L to (2*L) do begin
readln(f,u);
writeln(u);
writeln(q,u);
end;
end;
close(q);
close(w);
close(f);
writeln();
writeln('En loggfil har skapats. Den heter "logg.txt". Tryck ENTER.');
readln();
end.

255 is the max length of a string in pascal. you need to read in chunks of up to 255 bytes at a time.

I think it can be done with the read function, but my pascal is REALLY rusty, so you'll want to check on that

Okay, I'll see what I can make from that, thx

I worked it out. This is the way to do it. Can't belive I missed it before ;)


program openup; {By lingon}
uses
crt;
var
s, t : string;
f, p : text;
begin
clrscr;
write('Enter filename:');
readln(t);
assign(f,t);
assign(p,'logg.txt');
reset(f);
rewrite(p);
while not eof(f) do begin
readln(f,s);
writeln(s);
writeln(p,s);
end;
close(f);
close(p);
writeln();
writeln('A loggfile has been created. Press ENTER.');
readln();
end.

I'd look at using more meaningful variable name especially for when you start creating longer programs ... just a nod ;)

Will do, thanks :)










privacy (GDPR)