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

Works for me:

1,1,1,1
2,2,2,2
3,3,3,3
4,4,4,4
5,5,5,5

:-)

You are telling WriteFile to write 40 bytes (your buffer size) so it will write what you grab from the console, write them to file then write nulls.

That second CreateFile is NOT needed! You already created the file, and have a handle to the file.
change your WriteFiles to:

invoke  Str_length, addr buffer
    INVOKE  WriteFile,		; write text to file
            fileHandle,		; file handle
            ADDR buffer,		; buffer pointer
            eax,		; number of bytes to write
            ADDR bytesWritten,	; number of bytes written
            0

Yeah I wasn't sure if I needed that second create file but the program seemed to work so I left it in there but that's good to know of how to fix it. Thanks again your information is useful as always :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.