How to finish this program? Description: Write a program that creates a new text
ID: 3569984 • Letter: H
Question
How to finish this program?
Description: Write a program that creates a new text file.
Prompt the user for a student identification number, last name,
first name, and date of birth. Write this information to the file.
Input several more records in the same manner and close the file.
Note: see IrvineLibHelp.chm for irvine32 lib function
!
INCLUDE Irvine32.inc
GetInputField PROTO ptrPrompt:DWORD
.data
idStr BYTE "Enter ID number: ",0
lastNameStr BYTE "Enter last name: ",0
firstNameStr BYTE "Enter first name: ",0
bDateStr BYTE "Enter date of birth: ",0
crlfStr BYTE 0dh,0ah
errMsg BYTE "Cannot create file",0dh, 0ah, 0
fileName BYTE "studentFile.txt",0
fileHandle DWORD ?
buffer BYTE 300 DUP(0)
BufSize = $ - buffer
.code
main PROC
call CreateStudentFile
cmp eax, INVALID_HANDLE_VALUE
je error
; TODO: INVOKE GetInputField for idStr, lastNameStr, firstNameStr, bDateStr
; and write input the fields to file
error:
; TODO: Display errMsg
main ENDP
;-------------------------------------
CreateStudentFile PROC
; TODO: CreateOutputFile
ret
CreateStudentFile ENDP
;-------------------------------------
GetInputField PROC ptrPrompt:DWORD
; TODO: call ReadString
ret
GetInputField ENDP
;--------------------------------------
WriteToStudentFile PROC
; input: ECX = number of bytes
; TODO: call WriteToFile ; irvine32 lib function
ret
WriteToStudentFile ENDP
END main
Explanation / Answer
Creating a text file (note that this will overwrite the file if it already exists):
PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");
writer.println("The first line");
writer.println("The second line");
writer.close();
Creating a binary file (will also overwrite the file):
byte dataToWrite[] = //...
FileOutputStream out = new FileOutputStream("the-file-name");
out.write(dataToWrite);
out.close();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.