: : Can someone please help me to find out why the filehandling doesn't work? If you need to see the rest of the subroutines I will post them too. Thank you!!!
: :
: :
PROGRAM inlupp6(Input, Output);
: :
: : CONST
: : kundmax = 100;
: : kreditmax = 5000;
: :
: : TYPE
: : kundpektyp = ^transaktionstyp;
: : string_30 = PACKED ARRAY[1..30] of Char;
: : string_12 = PACKED ARRAY[1..12] of Char;
: : kundtyp = RECORD
: : namn : string_30;
: : gadress : string_30;
: : padress : string_30;
: : tele : string_12;
: : saldo : Integer;
: : kredit : Integer;
: : first : kundpektyp;
: : END; {kundtyp}
: : transaktionstyp = RECORD
: : datum : string_12;
: : transtyp : string_12;
: : transaktion : Integer;
: : next : kundpektyp;
: : END; {transaktionstyp}
: : regtyp = RECORD
: : kundarr : ARRAY[1..kundmax] of kundtyp;
: : antal : Integer;
: : END; {regtyp}
: : kundfil = FILE of kundtyp;
: : transfil = FILE of transaktionstyp;
: :
: : VAR
: : kom, svar : char;
: : kundreg : regtyp;
: :
: : PROCEDURE loadtrans(VAR kunden : regtyp);
: : VAR
: : tfil : transfil;
: : ny, sist : kundpektyp;
: : i : Integer;
: : BEGIN
: : RESET(tfil, 'transaktion.dat');
: : FOR i:=1 TO kunden.antal DO BEGIN
: : IF kunden.kundarr[i].first<>NIL THEN BEGIN
: : kunden.kundarr[i].first:=NIL;
: : REPEAT
: : New(ny);
: : Read(tfil, ny^);
: : IF kunden.kundarr[i].first=NIL THEN
: : kunden.kundarr[i].first:=ny
: : ELSE
: : sist^.next:=ny;
: : sist:=ny;
: : UNTIL ny^.next=NIL;
: : END; {IF}
: : END; {FOR}
: : END; {ladda}
: :
: : PROCEDURE loadkund(VAR kunden : regtyp);
: : VAR
: : kfil : kundfil;
: : BEGIN
: : RESET(kfil, 'kundreg.dat');
: : kunden.antal:=0;
: : WHILE NOT Eof(kfil) DO BEGIN
: : kunden.antal:=kunden.antal+1;
: : Read(kfil, kunden.kundarr[kunden.antal]);
: : loadtrans(kunden);
: : END; {WHILE}
: : END; {loadkund}
: :
: : PROCEDURE savekund(VAR kunden : regtyp);
: : VAR
: : fil1 : kundfil;
: : fil2 : transfil;
: : temp : kundpektyp;
: : i : Integer;
: : BEGIN
: : Rewrite(fil1, 'kundreg.dat');
: : Rewrite(fil2,'transaktion.dat');
: : FOR i:=1 TO kunden.antal DO BEGIN
: : Write(fil1, kunden.kundarr[i]);
: : temp:=kunden.kundarr[i].first;
: : WHILE temp<>NIL DO BEGIN
: : Write(fil2, temp^);
: : temp:=temp^.next;
: : END; {WHILE}
: : END; {FOR}
: : END; {savekund}
: :
: : BEGIN {HP}
: : Writeln('Welcome! ');
: : Writeln('Do you want to start? Y/N ');
: : Readln(svar);
: : svar:= versal(svar);
: : IF (svar='Y') THEN
: : loadkund(kundreg);
: : REPEAT
: : readkom(kom);
: : CASE kom OF
: : 'N' : donykund(kundreg);
: : 'T' : dotrans(kundreg);
: : 'S' : skriv_trans(kundreg);
: : 'Q' : ;
: : END; {CASE}
: : UNTIL kom='Q';
: : savekund(kundreg);
: : END.
: :
: :
: :
: If you are using TP, you first neet to call assign() before calling the reset() and after you have read/written the data, you need to call close(). Example:
:
: var
: f: file of char;
: begin
: Assign(f, 'test.dat'); { Connect the file variable to a filename }
: Rewrite(f); { Open the file for writing }
: write(f, 'b', 'l', 'a');
: Close(f); { Close the file connection, and release the file to the OS }
: end;
:
: If you are not using TP, I still think you need to close the file connection, but you need to find which procedure to call from the language documentation.
:
No- I'm using GNU Pascal and it would be wrong to close the files.. I have no idea what the problem is but I hope I'll find it out today.
Thank you anyway, it's great with such fast answers...