Re: Reading a table




CBFalconer <cbfalconer@xxxxxxxxx> wrote in message
news:474F95D6.ECFC9965@xxxxxxxxxxxx
Bill Reid wrote:
Roland Pibinger <rpbg123@xxxxxxxxx> wrote in message

... snip ...

- whithout static FILE

Possibly, but the idea here is just to read a single file and
then close it right up...

- for arbitrary long lines (no hard-coded maximum line lenght)

Yes, but again the idea here is we KNOW the maximum size> of our
file lines,

However, some people want to copy files without worrying about line
length. With ggets (and fggets) you can handle this with ease, as
in the following:

[1] c:\c\junk>cc -o fcopylns.exe ggets.o junk.c

[1] c:\c\junk>fcopylns <junk.c
#include <stdio.h>
#include <stdlib.h>
#include "ggets.h"

int main(void) {
char *line;

while (0 == ggets(&line)) {
puts(line);
free(line);
}
return 0;
} /* main, fcopylns */

Note the complexity. You can get the source etc. for ggets at:

<http://cbfalconer.home.att.net/download/ggets.zip>

Sure, something like that might come in handy in some situations,
but I actually take a somewhat different tack for parsing out text "tables"
with potentially (unpredictably) HUGE "field" sizes.

Consider that the file must STILL have a rigorously-applied delimiter
strategy in order to be useful. Then consider that we can always replace
the delimiter with '\0' in the text buffer, and that we can count the
"lines" (rows) as being every occurence of a '\n' OUTSIDE of a
potentially HUGE text field "protected" in some way to allow the
use of the "field" (columns) and "line" (rows) delimiters in the text.

So at the very least, if you use fgetc() until EOF, you will wind up
with a buffer of strings delimited by NULs that corresponds to your
count of "columns" and "rows", and if you haven't already completely
parsed out the data and assigned it to your arrays, you can make
a second pass to do so based on this information.

If you're wondering why you would want a second pass in the
first place, I actually do this on a weekly basis with some HUGE
text files (well, several MB each) I download from the net, and I
actually prefer for download speed and security to go through the
download buffers in real-time applying the NUL to each "field", and
then after closing each download connection doing some fairly
time-consuming parsing of the fields (which involves writing thousands
of files).

In this case, I'm always doing dynamic memory re-allocation
for the text buffer as the download buffer is filled on successive
HTTP GETs; in the case of local files, a similar type of dynamic
buffer re-sizing could also be used. Therefore, I never need to
"get" a "line" of any length at all...

But when it comes time to parse a file that I've written myself
and KNOW exactly how big the maximum line length is, I just
use fgets(), and typically nothing more fancy than sscanf() to parse
out and assign the "fields" for each line...

---
William Ernest Reid



.



Relevant Pages

  • Re: Assembly conversion to Pocket Pc format
    ... But in my case it is throwing exception before executing that statement what ... That is before reading buffer size it is throwing ... Stream respStream = resp.GetResponseStream; ... upload and download files in compact framework. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Implementing a "pull" (?) interface in perl
    ... # just parse what we have ... ## buffer if needing comment/cdata closure ... Use a schema checker ... Before you initiate parsing, you should validate the file, something ...
    (comp.lang.perl.misc)
  • Re: Implementing a "pull" (?) interface in perl
    ... # just parse what we have ... ## buffer if needing comment/cdata closure ... Use a schema checker ... Before you initiate parsing, you should validate the file, something ...
    (comp.lang.perl.misc)
  • Problem getting Access to separate fields of data
    ... assignment using "webcomputerassn" to download info into Access. ... dashed and forward slash key," as instructed but all I get is the boinking ... sound telling me, I assume, that I have chosen an incorrect function. ... the "delimiter" stage, please feel free to insult me and my entire family, ...
    (microsoft.public.access.forms)
  • Re: Memory Allocation in a Multi-Threaded Environment
    ... In general, I believe if you are sharing the same data between two threads, the design is ... A worker thread is created to read the entire file into a buffer whilst the ... catching up with the download. ... If you have to wait to resize until the processing is done, ...
    (microsoft.public.vc.mfc)