|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
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.
Code:
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.
|
|
#2
|
||||
|
||||
|
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
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide |
|
#3
|
||||
|
||||
|
Okay, I'll see what I can make from that, thx
|
|
#4
|
||||
|
||||
|
I worked it out. This is the way to do it. Can't belive I missed it before
![]() Code:
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.
|
|
#5
|
||||
|
||||
|
I'd look at using more meaningful variable name especially for when you start creating longer programs ... just a nod
![]()
__________________
--Ax without exception, there is no rule ... The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones ![]() 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski |
|
#6
|
||||
|
||||
|
Will do, thanks
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Pascal string problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|