Re: Newbie howto question.
- From: mwojcik@xxxxxxxxxxx (Michael Wojcik)
- Date: 27 Apr 2005 13:53:11 GMT
In article <aret61d4pj80qdtr3o65ateh11k3r1f87h@xxxxxxx>, rossum <rossum48@xxxxxxxxxxxx> writes:
> On Tue, 26 Apr 2005 00:19:00 -0000, Longfellow <not@xxxxxxxxxxxx>
> wrote:
>
>> I've got an ASCII text file (a GEDCOM file) comprised of many records of
>> tagged information. I've used an application to create a webpage for
>> each individual record, but now I want to add further information from
>> each record to the related web page....
>>
>> What I'm trying to figure out is an elegant way of inserting the
>> information into the correct place in the html file. All I can think to
>> do is read each html file into a buffer, testing for the relevant line,
>> then replace it with the revised line, and write the buffer back out
>> again, overwriting the file that was read in. What easier approach am I
>> missing?
>
> You don't have to read the whole file in at once. You can process it
> one line at a time, either copying the line unchanged or replacing it
> with an amended line.
More generally, file editing can be done with a buffer of any size
(provided you can store enough state to know what you're currently
looking at), from a bit to the entire file. Sometimes it's most
convenient to simply buffer the entire file, operate on the buffer,
and write it back out; often working with smaller pieces (and lines
are a typical choice for text files) is more suitable, and that
approach is often more space-efficient and scalable as well.
And despite what Phlip says, this is an easy task to accomplish in
C. It's moderately easier in higher-level languages, and if I were
doing it (again) I might use one, depending on other constraints;
but C will serve just fine, particularly since you can impose
restrictions on your input, since you know what it is. That means,
for example, that you can use a fixed-size line buffer and not worry
about over-long lines.
On the other hand, if you're just learning programming, learning a
higher-level language like Ruby or Python (Perl is also suitable, but
I don't recommend it, as its syntax is abominable and it suffers from
a surfeit of overlapping features) could be a useful educational
experience.
>> I'm using ANSI C and wish to avoid any non-standard usages.
It's impossible to write a non-trivial C program that doesn't depend
in some way on implementation-defined behavior, but you can accomplish
this task using only functions from the standard library, so you're in
good shape.
> remove(), rename() and tmpnam() are all in C99, I am not sure about
> ANSI C.
C99 is "ANSI C" - it's the most recent version of the ISO C standard,
which was adopted by ANSI. But remove, rename, and tmpnam have all
been part of the standard C library since the first ANSI standard.
>> I considered asking in comp.lang.c, but I get the feeling my question
>> isn't appropriate there.
I think it's on-topic for comp.lang.c, since it asks, in effect,
"what's a good way to accomplish this task using only the standard
features of the language?". However, you'd get the same answers you
got here.
--
Michael Wojcik michael.wojcik@xxxxxxxxxxxxxx
Pocket #16: A Ventriloquist's "Helper" -- Recordings for Divers Occasions,
especially cries to put in the mouths of enemies -- "God Bless Captain
Vere!" "Les jeux sont faits!" &c. -- Joe Green
.
- Follow-Ups:
- Re: Newbie howto question.
- From: rossum
- Re: Newbie howto question.
- From: Longfellow
- Re: Newbie howto question.
- References:
- Newbie howto question.
- From: Longfellow
- Re: Newbie howto question.
- From: rossum
- Newbie howto question.
- Prev by Date: Re: Writing a character to the beginning of the same file
- Next by Date: Re: Utilizing Idle Computer Resources
- Previous by thread: Re: Newbie howto question.
- Next by thread: Re: Newbie howto question.
- Index(es):
Relevant Pages
|