Re: Newbie howto question.
- From: rossum <rossum48@xxxxxxxxxxxx>
- Date: Tue, 26 Apr 2005 23:32:18 +0100
On Tue, 26 Apr 2005 00:19:00 -0000, Longfellow <not@xxxxxxxxxxxx>
wrote:
>I'm just learning how to program, so my question is probably elementary.
>Apologies where appropriate.
>
>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. Each html filename is $GEDCOM_ID
>with the '.html' suffix.
>
>So far, I can open the GEDCOM file and identify a record, and then open
>the related html file. I can identify the tagged information, extract
>said info and write it to the html file, closing the html file before
>going to the next record.
>
>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. This needs two files, so you will need to do a
bit of work with the file system:
BEGIN
open original file for reading
create a new temporary file for writing
read the first line from original file.
WHILE (not end of original file)
IF (line needs changing)
change the line as needed
write changed line to temporary file
ELSE
write original line to temporary file
ENDIF
read next line from original file
ENDWHILE
delete or rename original file
rename temporary file to the old name of the original file
END
>
>I'm using ANSI C and wish to avoid any non-standard usages.
remove(), rename() and tmpnam() are all in C99, I am not sure about
ANSI C.
>
>I considered asking in comp.lang.c, but I get the feeling my question
>isn't appropriate there. Read this NG charter, decided this was an
>algorithm matter, so posted here.
>
>All comments and replies appreciated.
>
>Thanks,
>
>Longfellow
The ultimate truth is that there is no ultimate truth
.
- Follow-Ups:
- Re: Newbie howto question.
- From: Michael Wojcik
- Re: Newbie howto question.
- References:
- Newbie howto question.
- From: Longfellow
- Newbie howto question.
- Prev by Date: Re: FNV(Fowler/Novell/Vo) hashing algorithm
- Next by Date: Re: Looking for Bin Packing Source Code, Packing Cartons
- Previous by thread: Re: Newbie howto question.
- Next by thread: Re: Newbie howto question.
- Index(es):
Relevant Pages
|