This message was edited by Phat Nat at 2005-5-31 17:36:12
: I'm wanting to create an account file that holds account information, eg:
: on my atm program it is possible to create a new account. What I don't know is how do I keep adding new accounts to this file?
If your account is stored as a record variable, it is quite easy. You can write the record to a file and then use the Append()
procedure to add on to a file if done in Text mode
if done in File Mode
(preferable). The only problem you'll have is if you need to delete a record, but even this is quite easy.
You can either have an array of your records or just one and read records from the file one-by-one until you find the one you want. The second way allows a huge size of records without trying to use pointers, etc.
If you want to delete a record the second method, you would have to copy your data file to another temp file, then copy it back over the original one record at a time and just don't copy the record you want to delete. Then delete the Temp file.
MyRecord = record
Name : String;
Age : Byte;
F : File;
Data : MyRecord;
X : Byte;
If IOResult <> 0 Then Rewrite(F,1);
X := 0;
While Not(Eof(F)) Do
WriteLn(' * Name = ',Data.Name);
WriteLn(' * Age = ',Data.Age);
While Keypressed Do Readkey;
Write('Name = ');
If Data.Name <> '' then
WriteLn('Age = ');
Here's an example of storing & Reading records to a file.