trinas1
asked on
Text File Editing Problem
I have created a text(.txt) file using the code below. I have to edit and
change the value of "Numberofbooks:= ?' .
How can I do this without altering (deleting) the rest of the file
Program Library;
Var
ArchBiblio:Text;
Code :String[10];
Namebook :String[50];
Numberofbooks :String[3];
Begin
Assign(ArchBiblio,'BIBLIOT EC.TXT');
Rewrite(ArchBiblio);
Code :='0001';
WriteLn(ArchBiblio,Code);
Namebook :='Chess Games';
WriteLn(ArchBiblio,Nameboo k);
Numberofbooks:='3';
WriteLn(ArchBiblio,Numbero fbooks);
Writeln(ArchBiblio);
Code :='0002';
WriteLn(ArchBiblio,Code);
Namebook :='Hello America';
WriteLn(ArchBiblio,Nameboo k);
Numberofbooks:='4';
WriteLn(ArchBiblio,Numbero fbooks);
Close(ArchBiblio);
End.
change the value of "Numberofbooks:= ?' .
How can I do this without altering (deleting) the rest of the file
Program Library;
Var
ArchBiblio:Text;
Code :String[10];
Namebook :String[50];
Numberofbooks :String[3];
Begin
Assign(ArchBiblio,'BIBLIOT
Rewrite(ArchBiblio);
Code :='0001';
WriteLn(ArchBiblio,Code);
Namebook :='Chess Games';
WriteLn(ArchBiblio,Nameboo
Numberofbooks:='3';
WriteLn(ArchBiblio,Numbero
Writeln(ArchBiblio);
Code :='0002';
WriteLn(ArchBiblio,Code);
Namebook :='Hello America';
WriteLn(ArchBiblio,Nameboo
Numberofbooks:='4';
WriteLn(ArchBiblio,Numbero
Close(ArchBiblio);
End.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank`s Bakry
Program Library_2;
Var
ArchBiblio:Text;
Code :String[10];
Namebook :String[50];
Numberofbooks :String[3];
Begin
Assign(ArchBiblio,'BIBLIOT
Reset(ArchBiblio);
{ first get the data that was stored in the file }
Read(ArchBiblio,Code);
Read(ArchBiblio,Namebook);
Read(ArchBiblio,Numberofbo
Read(ArchBiblio);
Close(ArchBiblio);
{ now close the file and reopen it to write data to it }
Assign(ArchBiblio,'BIBLIOT
Rewrite(ArchBiblio);
WriteLn(ArchBiblio,Code);
WriteLn(ArchBiblio,Nameboo
{ Here is where you want to make the
change }
Numberofbooks:='your choice';
WriteLn(ArchBiblio,Numbero
Writeln(ArchBiblio);
Close(ArchBiblio);
I understand what you want to do. You want to change one line the file without actually changing anything else!
That cannot be done without rewriting the file. You must first store the data of the file into your variables as shown above then make the neccesary changes you wish and write it back to the file.
End.