Science and TechnologySEE 2081

Rewrite the given program after correcting the bugs: REM to add record in an existing file. OPEN "student.dat" FOR OUT AS 2 TOP: INPUT "Enter Name, Class and Roll No."; SName$, C, RN INPUT 2,…

2

Rewrite the given program after correcting the bugs: REM to add record in an existing file. OPEN "student.dat" FOR OUT AS #2 TOP: INPUT "Enter Name, Class and Roll No."; SName$, C, RN INPUT #2, SName$, C, RN INPUT "More records"; Y$ IF UCASE$(Y$)="Y" THEN GOTO TOP CLOSE #2 STOP

Answer

REM to add record in an existing file.
OPEN "student.dat" FOR APPEND AS #2
TOP:
INPUT "Enter Name, Class and Roll No."; SName$, C, RN
PRINT #2, SName$, C, RN
INPUT "More records"; Y$
IF UCASE$(Y$)="Y" THEN GOTO TOP
CLOSE #2
END

Explanation:

  • Changed FOR OUT to FOR APPEND to allow adding records to an existing file without overwriting.
  • Replaced INPUT #2, with PRINT #2, to correctly write data to the file.
  • Replaced STOP with END for proper program termination.

Discussion

Loading…

More Science and Technology questions

All Science and Technology old questions