A Textfile like this:
This is test one.
This is test two.
This is test three.
How can I readfile to get one text line("This is test one")
by one time?HOr get one word ("This")
How can I know the eof of text line ?
Sorry my English not well?I
This is test one.
This is test two.
This is test three.
How can I readfile to get one text line("This is test one")
by one time?HOr get one word ("This")
How can I know the eof of text line ?
Sorry my English not well?I
There are a number of ways of doing this but unless you have truly enormous files, I would be inclined to read it fully into memory and then scan through it from the start to the next CRLF (13,10) copying the data into a seperate buffer, line by line. Then you can sub process it for individual words and write each line back to a file or another buffer.
Regards,
hutch@movsd.com
Regards,
hutch@movsd.com
Thank you very much!
Could you tell me more detail,
such as by windows api (CreateFile,ReadFile,...)
to deal with this problem?
Could you tell me more detail,
such as by windows api (CreateFile,ReadFile,...)
to deal with this problem?
This is what hutch is saying:
1) use CreateFile to open the file
2) use GetFileSize to get the size of the file
3) use the value returned from step two to allocate a buffer
4) Use ReadFile to read the entire contents into above buffer
5) Do pparsing ojn the buffer in windows a crlf pair indicates the end of a line
1) use CreateFile to open the file
2) use GetFileSize to get the size of the file
3) use the value returned from step two to allocate a buffer
4) Use ReadFile to read the entire contents into above buffer
5) Do pparsing ojn the buffer in windows a crlf pair indicates the end of a line
This is what hutch is saying:
1) use CreateFile to open the file
2) use GetFileSize to get the size of the file
3) use the value returned from step two to allocate a buffer
4) Use ReadFile to read the entire contents into above buffer
5) Do pparsing ojn the buffer in windows a crlf pair indicates the end of a line
thanks.
invoke CreateFile,ADDR buffer,\
GENERIC_READ or GENERIC_WRITE ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
invoke GetFileSize,hFile,0
mov fsize,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,fsize
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
;invoke ReadFile,hFile,pMemory,fsize,ADDR SizeRead,NULL
invoke ReadFile,hFile,pMemory,4,ADDR SizeRead,NULL
After the four step,How can I show pMemory to MessageBox?
?????
invoke MessageBox, NULL,addr pMemory, addr pMemory, MB_OK
?????
invoke CloseHandle,hFile
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
pMemory is allready the address of the text read from the file so you don't need to use addr
invoke MessageBox, NULL,pMemory, pMemory, MB_OK
Thanks.
now read it fully into memory.
invoke ReadFile,hFile,pMemory,fsize,ADDR SizeRead,NULL
Last step.
1)How do I get one byte from pMemory?
2)when I get byte one to byte1 and the next byte to byte2,
is following scan correct?
.IF (byte1== 0dh && byte2 == 0Ah)
...
.ENDIF
now read it fully into memory.
invoke ReadFile,hFile,pMemory,fsize,ADDR SizeRead,NULL
Last step.
1)How do I get one byte from pMemory?
2)when I get byte one to byte1 and the next byte to byte2,
is following scan correct?
.IF (byte1== 0dh && byte2 == 0Ah)
...
.ENDIF
fox,
use the search engine and search for "line input". This will bring up some examples.
When I am back at home, I can post some source if you want me to.
Regards,
bAZiK
use the search engine and search for "line input". This will bring up some examples.
When I am back at home, I can post some source if you want me to.
Regards,
bAZiK
bAZiK,
Thank you very much.
Post some source ,please!
Regards,
Fox
Thank you very much.
Post some source ,please!
Regards,
Fox
bAZiK,
Thank you very much.
Post some source ,please!
Regards,
Fox
Before I post you the solution, you should use the search engine as I suggested and try to find it our yourself:
http://www.asmcommunity.net/board/index.php?topic=523&highlight=line+input
This is the way to go if you want to learn Win32ASM ;)
bAZiK,
Thank you very much.
I will try my best to use the search engine,
And find problem out myself.
Thank you very much.
I will try my best to use the search engine,
And find problem out myself.
Method #1: Reading full file into memory and scanning for CR+LF
Pros: pretty fast
Cons: not good for large files
Method #2: memory mapped files
Pros: as easy as method #1, can handle "larger text files than you'll ever need"
Cons: memory mapped files are slow (slower than direct filereading anyway)
Method #3: processing file in chunks
Pros: pretty fast, can handle any size files, not too bad memory overhead
Cons: more complicated to code, as you need to handle lines that span buffersize.
Method #4: getting one byte at a time
Pros: a bit easier to code than method #3
Cons: slow, even if you buffer the input
...
Any other ideas?
Pros: pretty fast
Cons: not good for large files
Method #2: memory mapped files
Pros: as easy as method #1, can handle "larger text files than you'll ever need"
Cons: memory mapped files are slow (slower than direct filereading anyway)
Method #3: processing file in chunks
Pros: pretty fast, can handle any size files, not too bad memory overhead
Cons: more complicated to code, as you need to handle lines that span buffersize.
Method #4: getting one byte at a time
Pros: a bit easier to code than method #3
Cons: slow, even if you buffer the input
...
Any other ideas?