- Reading CR-LF delimited lines from a text-file ?
- Posted by R.Wieser on October 18th, 2003
Hello All,
I've got a text-file (actually, am e-mail message), and want to read the
lines form it one at a time. For some reason I can't seem to find a
switch/method that switches the file/read-mode from binary to text.
My question : *can* I switch the read-mode from binary to text, or must I
write my own file-buffering & line-by-line reading routines ?
Regards,
Rudy Wieser
- Posted by Ralf Buschmann on October 18th, 2003
On Sat, 18 Oct 2003 19:04:47 +0200, "R.Wieser"
<rwieser-killthis-@xs4all.nl> wrote:
Use the CRT functions (fopen(), fgets()) to read the file.
Ralf.
- Posted by R.Wieser on October 18th, 2003
Ralf Buschmann <caranthir2@dev_null.gmx.de> schreef in berichtnieuws
3f91771a$0$60771$afc38c87@auth.de.news.easynet.net ...
Hello Ralf,
I would like to, but alas, I can't find those functions :-(
Actually, I forgot to say that I'm using Assembly (Tasm 5.0), and am
restricted to the DLL's offered to me by the OS :-)
But that does not mean I'm not apriciating your answer !
Regards,
Rudy Wieser
- Posted by Raymond Chen on October 19th, 2003
In which case you can use CreateFile to open the file and
ReadFile to read from it. (And CloseHandle to close the handle.)
"Text mode vs binary mode" is a runtime concept. Since you aren't
using any runtime library, you are talking directly to files. How
you choose to interpret the bytes in the file is entirely up to
you.
On Sat, 18 Oct 2003 20:44:46 +0200, "R.Wieser"
<rwieser-killthis-@xs4all.nl> wrote:
- Posted by R.Wieser on October 19th, 2003
Raymond Chen <http://guest@blogs.gotdotnet.com/raymondc/> schreef in
berichtnieuws rcj3pvor6f01icmd2iskhl0v4ci1v2235u@4ax.com...
Hello Raymond,
That was as far as I got :-)
Well, If I take my knowledge of DOS as a comparision, I seem to remember I
could switch the file-mode (Using an I/O-control command) to interpret
CTRL-C and Ctrl-Z and CR-LF as special characters. :-)
I was actually hoping that I could do something alike in the
Windows-environment (Sought for it on the Web, but could not find anything)
....
Oh, well. It just means that I have to write those routines (buffering
data-blocks & interpret the contents byte-by-byte) myself :-)
Thanks for your answer.
Regards,
Rudy Wieser
- Posted by MrBCX on October 19th, 2003
"R.Wieser" <rwieser-killthis-@xs4all.nl> wrote in message news:<3f917475$0$145$e4fe514c@dreader5.news.xs4all .nl>...
This is not intended to be a shameless plug.
The following text about the "SPLIT Function" comes from the
BCX (BASIC TO C TRANSLATOR) Help file. Amoung its numerous other
strengths, BCX makes dealing with delimited text files childs play.
BCX's output (c source code) specifically targets the Lcc-Win32
compiler. However, other compilers, Mingw, Pelles, DigitalMars,
Intels, Borland, VC++, have also been used with little modification.
Start here: http://bcx.basicguru.com ... Good luck!
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
=
SPLIT function
Purpose: SPLIT parses a string separated by delimiters, copies the
parsed elements to an array and returns the number of parsed elements
that were copied to the array. Parsed strings are stored starting at
array element zero. The delimiter can be composed of a single or
multiple characters. The delimiters can also be saved to the array by
setting the optional SaveDelimitFlag parameter to 0, 1, 2 or 3. This
gives the user the following 4 options regarding the parsing behavior
of the SPLIT and DSPLIT functions:
0 = Eliminate all delimiters (default behavior)
1 = Retain all delimiters and all null fields
2 = Eliminate all delimiters and null fields
3 = Retain all delimiters excluding null fields
In default mode, 0, SPLIT strips quotation marks from quoted fields
and is VB6 compatible handling null fields.
When using options 1 or 3, in addition to the delimiters being
included into the users parse stack, quoted strings stay quoted.
Syntax:
RetVal% = SPLIT(OneDIMArray$, _
StringToParse$, _
Delimiter$ _
[,SaveDelimitFlag])
Parameters
RetVal% Number of parsed elements that were copied to OneDIMArray$.
OneDIMArray$ One dimensional array to hold elements of parsed
StringToParse$. Parsed strings are stored starting at array element
zero. Note well that the lower bound of the OneDIMArray$ subscripts
can not be set using OPTION BASE.
StringToParse$ String to parse containing by delimited elements.
Delimiter$ The delimiter can be composed of a single or multiple
characters. The delimiters can also be saved to the array by setting
the SaveDelimitFlag flag to TRUE.
SaveDelimitFlag OPTIONAL flag to save delimiters to the array.
0 = Eliminate all delimiters (default behavior)
1 = Retain all delimiters and all null fields
2 = Eliminate all delimiters and null fields
3 = Retain all delimiters excluding null fields
Example 1 :
DIM i%, j%, A$, Buffer$[12]
A$ = "1,2;3 ,4;5,6, 7,8;9"
i% = SPLIT( Buffer$, A$, ", ;")
PRINT "Split returns the value of", i
FOR j% = 0 TO i%-1
PRINT Buffer$[j%]
NEXT
Result:
Split returns the value of 12
1
2
3
4
5
6
7
8
9
Example 2 :
CLS
DIM A$[100], B$, I, J
B$ = "Here is,,," & CHR$(34) & "New,Test" & CHR$(34) & ";Test!"
I = SPLIT(A$, B$, ",;+")
PRINT "Sample String = ", B$
PRINT "************************************************"
PRINT I , " Eliminate all delimiters (default behavior)"
PRINT "************************************************"
FOR J = 0 TO I-1
PRINT "[",J,"] LEN=", LEN(A$[J])," Cell =" , A$[J]
NEXT
PRINT
I = SPLIT(A$, B$, ",;+", 1)
PRINT "************************************************"
PRINT I , " Retain all delimiters and all null fields"
PRINT "************************************************"
FOR J = 0 TO I-1
PRINT "[",J,"] LEN=", LEN(A$[J])," Cell =" , A$[J]
NEXT
PRINT
I = SPLIT(A$, B$, ",;+", 2)
PRINT "************************************************"
PRINT I , " Eliminate all delimiters and null fields"
PRINT "************************************************"
FOR J = 0 TO I-1
PRINT "[",J,"] LEN=", LEN(A$[J])," Cell =" , A$[J]
NEXT
PRINT
I = SPLIT(A$, B$, ",;+", 3)
PRINT "************************************************"
PRINT I , " Retain all delimiters excluding null fields"
PRINT "************************************************"
FOR J = 0 TO I-1
PRINT "[",J,"] LEN=", LEN(A$[J])," Cell =" , A$[J]
NEXT
Result:
Sample String = Here is,,,"New,Test";Test!
***********************************************
5 Eliminate all delimiters (default behavior)
***********************************************
[ 0] LEN= 7 Cell =Here is
[ 1] LEN= 0 Cell =
[ 2] LEN= 0 Cell =
[ 3] LEN= 8 Cell =New,Test
[ 4] LEN= 5 Cell =Test!
***********************************************
9 Retain all delimiters and all null fields
***********************************************
[ 0] LEN= 7 Cell =Here is
[ 1] LEN= 1 Cell =,
[ 2] LEN= 0 Cell =
[ 3] LEN= 1 Cell =,
[ 4] LEN= 0 Cell =
[ 5] LEN= 1 Cell =,
[ 6] LEN= 10 Cell ="New,Test"
[ 7] LEN= 1 Cell =;
[ 8] LEN= 5 Cell =Test!
***********************************************
3 Eliminate all delimiters and null fields
***********************************************
[ 0] LEN= 7 Cell =Here is
[ 1] LEN= 8 Cell =New,Test
[ 2] LEN= 5 Cell =Test!
***********************************************
7 Retain all delimiters excluding null fields
***********************************************
[ 0] LEN= 7 Cell =Here is
[ 1] LEN= 1 Cell =,
[ 2] LEN= 1 Cell =,
[ 3] LEN= 1 Cell =,
[ 4] LEN= 10 Cell ="New,Test"
[ 5] LEN= 1 Cell =;
[ 6] LEN= 5 Cell =Test!
- Posted by Joakim Braun on October 19th, 2003
Why not use C++ standard library streams and getline()? Those streams have
switches for text/binary modes.
Joakim Braun
"R.Wieser" <rwieser-killthis-@xs4all.nl> skrev i meddelandet
news:3f9246ef$0$133$e4fe514c@dreader5.news.xs4all. nl...
- Posted by R.Wieser on October 19th, 2003
Joakim Braun <joakim.braun@jfbraun.removethis.com> schreef in berichtnieuws
foykb.383$947.324@nntpserver.swip.net...
I'm not quite sure ... Maybe because I want to know, outside of the
standard DLL's (and often even within), what's going on under the hood. To
me programming is not only a means to a result, but allso a means to explore
& learn. :-)
Thanks for the suggestion though. Maybe I could try to find some
source-file of these C(++) file-streaming functions.
Regards,
Rudy Wieser
- Posted by Ralf Buschmann on October 20th, 2003
On Sat, 18 Oct 2003 20:44:46 +0200, "R.Wieser"
<rwieser-killthis-@xs4all.nl> wrote:
CRTDLL.DLL
Ralf.
- Posted by R.Wieser on October 20th, 2003
Ralf Buschmann <caranthir2@dev_null.gmx.de> schreef in berichtnieuws
3f938a6f$0$60769$afc38c87@auth.de.news.easynet.net ...
Hello Ralf,
Yep, it's there allright (I did think you ment a group of functions, not a
DLL ...). I did search for "stdio.*" (the C-library), but did not think
about looking for this one :-\ I think that this will make my life
somewhat easier :-)
Thanks for the pointer. Now all I need to do is to find a good description
of the functions in that DLL :-) My current documentation (a Help-file
stating "Microsoft® Win32® Programmer's Reference") does not even know of
the existence of "fopen" and consorts :-\ Back to the Web-searches
(Googeling) !
Regards,
Rudy Wieser
- Posted by Ralf Buschmann on October 20th, 2003
On Mon, 20 Oct 2003 11:31:51 +0200, "R.Wieser"
<rwieser-killthis-@xs4all.nl> wrote:
If you have MSVC++ and/or MSDN, it's all documented in the MSDN Library.
Or online at
http://msdn.microsoft.com/library/en...nreference.asp
Ralf.
- Posted by R.Wieser on October 20th, 2003
Ralf Buschmann <caranthir2@dev_null.gmx.de> schreef in berichtnieuws
3f93b979$0$60771$afc38c87@auth.de.news.easynet.net ...
Hello Ralf,
reference.asp
I'm *very* glad you're offering me the above pointer, as I've just have had
a 2+ -hour Google-session, with disappointing little in regard to a result
(read this as : I came up with nothing usable) .. :-\
I just visited the pages, and allread have found, next to them being
helpfull, a mistake in my assumptions : In CRTDLL.DLL the "CRT"-bit doesn't
mean "Cathode-Ray Tube" (monitor for short) , but actually ment "C
Run-Time". I think that me remembering the first is actually a sign of how
dated I am :-)
Thanks again.
Regards,
Rudy Wieser
- Posted by Ralf Buschmann on October 20th, 2003
On Mon, 20 Oct 2003 15:02:34 +0200, "R.Wieser"
<rwieser-killthis-@xs4all.nl> wrote:
LOL! :-) Anyway, glad I could help.
Ralf.