flat assembler
Message board for the users of flat assembler.

Index > Windows > Reading from text file

Author
Thread Post new topic Reply to topic
miksayer



Joined: 14 Jul 2005
Posts: 17
Location: Belarus
miksayer 14 Jul 2005, 21:07
How can I to read from text file?
Post 14 Jul 2005, 21:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Jul 2005, 21:31
just like from binary file, there is no difference, but you have to code all routines like word-recognising, finding end-of-line etc. yourself. one of biggest disadvantages of ASM - you don't have standard libraries
Post 14 Jul 2005, 21:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
afw2004



Joined: 16 Jun 2005
Posts: 49
Location: Kharkov, Ukraine
afw2004 15 Jul 2005, 10:01
If you are writing program for Windows, you can use function from msvcrt.dll library. For example:


Code:
READ_ACCEDD db 'r',0

proc read_text_file, .pszFileName
local .tfile:dword, .pStrBuf:dword

    push ebx edi esi

    invoke LocalAlloc, LMEM_FIXED or LMEM_ZEROINIT,1024   ; Allocate space for string to read
    mov [.pStrBuf],eax
    
    cinvoke fopen, [.pszFileName],READ_ACCESS   ; Open text file for reading
    mov [.tfile],eax

.startloop:   ; Get string from text file one by one and store it in [.pStrBuf]
    cinvoke fgets, [.pStrBuf],1024,[.tfile]
    test eax,eax
    jnz .startloop

    cinvoke flose, [.tfile]
    invoke LocalFree, [.pStrBuf]

    pop esi edi ebx
    ret
endp
    
Post 15 Jul 2005, 10:01
View user's profile Send private message ICQ Number Reply with quote
miksayer



Joined: 14 Jul 2005
Posts: 17
Location: Belarus
miksayer 15 Jul 2005, 10:04
afw2004, thank you!
Post 15 Jul 2005, 10:04
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 15 Jul 2005, 19:50
i'd recommend you to use pure windows api (CreateFile, ReadFile, CloseHandle)
Post 15 Jul 2005, 19:50
View user's profile Send private message Reply with quote
rwalt



Joined: 27 Apr 2004
Posts: 19
Location: Illinois, USA
rwalt 16 Jul 2005, 04:18
MSVCRT.DLL is a part of the Microsoft Win32 API. It is not one of the core libraries, but it is a member of the API. I believe also that CreateFile and ReadFile may actually make calls to some of the file handling procedures in the C runtime libraries.

_________________
DarkStar
Post 16 Jul 2005, 04:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 16 Jul 2005, 10:21
Actually it's the other way round. Also, you will not find the MSVCRT functions in the Microsoft's Win32 API reference.
Post 16 Jul 2005, 10:21
View user's profile Send private message Visit poster's website Reply with quote
miksayer



Joined: 14 Jul 2005
Posts: 17
Location: Belarus
miksayer 16 Jul 2005, 16:02
Quote:

Also, you will not find the MSVCRT functions in the Microsoft's Win32 API reference.

why?
Post 16 Jul 2005, 16:02
View user's profile Send private message Reply with quote
rwalt



Joined: 27 Apr 2004
Posts: 19
Location: Illinois, USA
rwalt 19 Jul 2005, 04:41
Yes, your correct, I should have held back on my reply. Embarassed

_________________
DarkStar
Post 19 Jul 2005, 04:41
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 19 Jul 2005, 23:49
miksayer wrote:
Quote:

Also, you will not find the MSVCRT functions in the Microsoft's Win32 API reference.

why?
Microsoft's Win32 API reference as it's name suggests is only about APIs shared for ALL windows programs. MSVCRT is C/C++ library only. It doesn't mean one cannot use it in asm/delphi/vb/... but it is not their purpose.
But you can find all needed info in C/C++ reference (just as: www.msdn.com)
Post 19 Jul 2005, 23:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.