Hi all!
How can I read file line by line as I do it in VB-programs:

Open "c:\autoexec.bat" for Input as #1
Do while not eof(1)
Line Input #1, strBuffer
Posted on 2001-08-06 06:36:45 by vkim

Basic's Line Input statement reads a line of text from a buffer read from disk from the end of one CRLF pair to another.

You have a few ways of doing it but I would recommend if the data to be read is not too big is to load the whole file in memory and byte scan it until you find the 13,10, copy it to where you want and advance up to the next one. You will have a reusable buffer that you write to each time, append an ascii zero onto the end when its written and copy that buffer to where you want.

The byte scan is not hard to do, load the file into memory and get the address of the memory, put it into a register,

mov esi, lpFile
mov edi, lpBuffer

and make a loop to read each byte, compare it to 13 and keep reading till the next 13.

mov al,
inc esi
cmp al, 13
je nxtlabel
mov , al
inc edi
; etc ....


Posted on 2001-08-06 07:30:11 by hutch--
Here is a way it could be done.


FileName db "C:\MyDir\MyFile.txt",0


ReadFile proc uses esi edi
LOCAL fBuff[4096]:BYTE
LOCAL Line[2048]:BYTE

;Open file
invoke CreateFile,addr FileName,GENERIC_READ,
mov hFile,eax
invoke GetFileSize,hFile,NULL
mov fSize,eax
lea edi,Line
mov nBytes,0
;Read file in chuncs sizeof fBuff
.while fSize
.if !nBytes
;Fill buffer with data
mov eax,sizeof fBuff
mov nBytes,eax
invoke ReadFile,hFile,addr fBuff,nBytes,addr nBytes,0
mov eax,nBytes
sub fSize,eax
lea esi,fBuff
mov al,[esi]
mov [edi],al
inc esi
inc edi
.if al==0Ah
;Edd of line
mov byte ptr [edi],0
push esi
;Process the line here
mov nBytes,0
pop esi
lea edi,Line
invoke CloseHandle,hFile

ReadFile endp

If your file is small then you could read the whole
file in one chunk and the code would be much simpler.
Posted on 2001-08-06 07:38:06 by KetilO