получаю ошибку - Error 105: File not open for output.
Program ch;
Var
f1, f2: text; a,n: byte; count: integer; stroka, stroka1, stroka2: string;
begin
a:=2;
n:=4;
assign (f1, 'file1.txt');
assign (f2, 'file2.txt');
reset (f1);
rewrite (f2);
count:=0;
while not eof (f1) do begin
readln (f1, stroka);
if count=a then
writeln (f2, stroka1);
if count=n then
writeln (f2, stroka2);
count:= count+1;
end;
begin
reset (f2);
rewrite (f1);
count:=1;
if count=a then
readln (f2, stroka2);
writeln (f2, stroka);
if count=a then
readln (f2, stroka1);
writeln (f2, stroka);
count:= count+1;
end;
close (f1);
close (f2);
erase (f2);
end.
reset (f2);
// ...
writeln (f2, stroka);
reset (f2);
// ...
writeln (f2, stroka);
может, задание расскажешь? или это тайна?
текстовый файл можно открыть или для записи, или для чтения. делать и то, и другое одновременно не получится.
readln (f2, stroka2);
writeln (f2, stroka);
readln (f2, stroka2);
writeln (f2, stroka);
Program ch;
Var
f1, f2: text; a,n: byte; count: integer; stroka, stroka1, stroka2: string;
begin
a:=2;
n:=4;
assign (f1, ‘file1.txt’);
assign (f2, ‘file2.txt’);
reset (f1);
rewrite (f2);
count:=0;
while not eof (f1) do begin
readln (f1, stroka);
if count=a then
writeln (f2, stroka1);
if count=n then
writeln (f2, stroka2);
count:= count+1;
end;
begin
reset (f2);
rewrite (f1);
count:=1;
if count=a then
readln (f2, stroka2);
writeln (f1, stroka);
if count=a then
readln (f2, stroka1);
writeln (f1, stroka);
count:= count+1;
end;
close (f1);
close (f2);
erase (f2);
end.
у меня получается?
если было
1
2
то получается
2
2
где я не то пишу?
Что-то вроде этого, но думаю можно это делоа сократить. Причем серьезно.
var
f1, f2: Text;
s, first: String;
n, m, count: Integer;
begin
n := 2;
m := 3;
if n <> m then begin
assign(f1, 'text.txt'); reset(f1);
assign(f2, 'temp.txt'); rewrite(f2);
count := 0;
while not(eof(f1)) and (count < n - 1) do begin
readln(f1, s); inc(count);
writeln(f2, s);
end;
readln(f1, first);
reset(f1); count := 0;
while not(eof(f1)) and (count <> m) do begin
inc(count);
readln(f1, s);
end;
writeln(f2, s);
reset(f1); count := 0;
while not(eof(f1)) do begin
readln(f1, s); inc(count);
if count = m then writeln(f2, first) else
if count > n then writeln(f2, s);
end;
close(f1); close(f2);
rename(f1, 'to_delete.txt');
rename(f2, 'text.txt');
erase(f1);
end;
end.
klem4, спасибо!!!!!!!!
Большое спасибо!