Hi I'm stumped on how to make this program that I'm working on to output the information to the text file in a nice fashion instead of writing it in a funny way. I basically want this program to output the student record information line by line and organized. The program works but just don't know how to make the information look nice. Thanks!
INCLUDE Irvine32.inc
.data
before BYTE "This program runs until 5 student records are entered.",0
intro BYTE "Please enter your student ID number, last name, first name, and date of birth in this order: ",0
errMsg BYTE "Cannot create file",0dh,0ah,0
filename BYTE "output.txt",0
fileHandle DWORD ? ; handle to output file
bytesWritten DWORD ? ; number of bytes written
stdInHandle HANDLE ?
BufferSize = 40
buffer BYTE BufferSize DUP(?)
bytesRead DWORD ?
.code
main PROC
mov edx,OFFSET before
call WriteString
call crlf
mov ebx,0
RecordEntry:
mov edx,OFFSET intro
call WriteString
INVOKE GetStdHandle, STD_INPUT_HANDLE
mov stdInHandle,eax
INVOKE ReadConsole, stdInHandle, ADDR buffer,
BufferSize, ADDR bytesRead, 0
INVOKE CreateFile,
ADDR filename, GENERIC_WRITE, DO_NOT_SHARE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
mov fileHandle,eax ; save file handle
.IF eax == INVALID_HANDLE_VALUE
mov edx,OFFSET errMsg ; Display error message
call WriteString
mov eax,0
jmp RecordEntry
.ENDIF
INVOKE WriteFile, ; write text to file
fileHandle, ; file handle
ADDR buffer, ; buffer pointer
BufferSize, ; number of bytes to write
ADDR bytesWritten, ; number of bytes written
0 ; overlapped execution flag
Records:
inc ebx
cmp ebx,5
je theend
mov edx,OFFSET intro
call WriteString
INVOKE GetStdHandle, STD_INPUT_HANDLE
mov stdInHandle,eax
INVOKE ReadConsole, stdInHandle, ADDR buffer,
BufferSize, ADDR bytesRead, 0
INVOKE CreateFile,
ADDR filename,
GENERIC_WRITE, ; access mode
DO_NOT_SHARE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0
INVOKE SetFilePointer,fileHandle,0,0,FILE_END
INVOKE WriteFile, ; write text to file
fileHandle, ; file handle
ADDR buffer, ; buffer pointer
BufferSize, ; number of bytes to write
ADDR bytesWritten, ; number of bytes written
0 ; overlapped execution flag
jmp Records
INVOKE CloseHandle, fileHandle
theend:
exit
main ENDP
END main