Article View: comp.lang.modula2
Article #2977Re: Arrays of Records and Sequential File Reading
From: robert leroux
Date: Mon, 30 Oct 1995 13:53
Date: Mon, 30 Oct 1995 13:53
112 lines
4665 bytes
4665 bytes
In article <DH2EpC.MIo@cix.compulink.co.uk>, mark_tbu@cix.compulink.co.uk ("Mark Morgan Lloyd ") says:
>
>> In article <DGysxx.98u@cix.compulink.co.uk>,
>> mark_tbu@cix.compulink.co.uk ("Mark Morgan Lloyd ") says:
>> >
>> >Post the appropriate part of your code here and let's see what we can
>> do. >It'll make a change from all this cross-posted wibble about Ada vs
>> C++ >(or ADA vs Fortran, as one participant would have it).
>> >
>> >Mark Morgan Lloyd
>> >mark_tbu@cix.compulink.co.uk
>> >
>> >[Opinions above are the author's, not those of his employers or
>> >colleagues]
>>
>
>YHM
>
>>
>> Thanks for responding.
>>
>> I darn near have the program working. I just have to read in a string
>> from the keyboard and compare it to the revelant record. I am doing
>> this as per following program snippet:
>>
>> IF IsMatch = Str.Match (title,singlebook[x].TITL THEN
>> (*print the whole RECORD of singlebook[x].????*)
>> ELSE
>> (*Display to user that no match was found. Then loop back to start
>> of program to allow another search*)
>>
>> I am using 'x.' so that the whole ARRAY will be searched along with the
>> field.
>> IsMatch is declared as a BOOLEAN.
>>
>> Am I on the right track?
>>
>
>Not quite sure here what you mean by "I am using 'x.'" etc. Also, is that
>boolean expression quite right, or do you mean IF Str.Match() ?
>
>> As for the actual record:
>>
>> BOOK = RECORD
>> TITL : Title; (*TITL, AUTH, COPI AND DATE are an ARRAY
>of CHAR*)
>> AUTH : Author;
>> COPI : String;
>> DATE : Due; (*Eventually this will be arrayed so that
>I can have up
>> to END; four Dates per book*)
>>
>> Library = ARRAY [1..maxbook] OF BOOK; (*according to all the
>> references I read, this line should take the four fields in record BOOK
>> and address them per ARRAY until it reaches the maximum or before (if
>> the data file is shorter than maxbook)).
>>
>
>What functions are you using to write and read the file? In general, they
>won't know about your data representation, so it's down to you to check
>for EOF etc.
>
>> I found out that this is not the case, since my data file is set up
>> like:
>> TITL
>> AUTH
>> COPI
>> DATE
>> :
>> :
>> DATE
>>
>> maxbook relates to the number of lines in the data file.
>>
>> After some work the other day, I successfully called random
>fields,
>> within the program, from the array and displayed them. I did this by
>> changing the 'x' to 1, 2, 3 . . . for whatever book II wanted along
>> with the field. This is what I initially had problems with. Now when
>> I do a search from the keyboard to find the title of a book for
>> instance, I can pull up anything I want, which should not be.
>> Is it something to do with the variable 'x' as noted above with
>the
>> Match. Or should I approach this from a different angle.
>>
>> Thanks.
>>
>> rleroux@direct.ca
>>
>
>Hope that's been of some help
>
>Mark Morgan Lloyd
>
Sorry for taking so long to respond.
First of all you were right in that IsMatch := Str.Match is not the same as
Str.Match(); I did not realize that Str.Match is a boolean function. After fixing
that bug I have moderate success with the program. However, when I search the library,
I am using a REPEAT/UNTIL loop with my IF Str.Match(title,singlebook[x].TITLE) THEN
in between. If a match is found then I print out the Title of the specific book, If the
title is not found in the library, then I print out that the title is not found, but during
the search of the library until my 'x' := maxbook, I end up printing out 'book not found' until
I find a match. I thought of changing the REPEAT loop to a FOR...NEXT loop, similar to what
Dieter. W. wrote in his response. Will this solve the problem or should I change to a WHILE loop?
As for your last question of how I am handleing the files. I am reading them from a text file
using FIO.RdStr, I will be writing the results back to disk once I have this program operating correctly
using FIO.WrStr and FIO.WrCard (for the Date field).
Robert. Leroux
Technical Details
Message-ID:
<472lcc$kdk@grid.Direct.CA>Path:
arc1-ca.pugleaf.net!newsfeed.direct.ca!usenetReferences:
<46ngu2$r72@grid.Direct.CA> <DH2EpC.MIo@cix.compulink.co.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsfeed.direct.ca!usenet From: rleroux@direct.ca (robert leroux) Newsgroups: comp.lang.modula2 Subject: Re: Arrays of Records and Sequential File Reading Date: 30 Oct 1995 13:53:16 GMT Organization: Internet Direct Inc. Message-ID: <472lcc$kdk@grid.Direct.CA> References: <46ngu2$r72@grid.Direct.CA> <DH2EpC.MIo@cix.compulink.co.uk> NNTP-Posting-Host: 204.174.243.27 X-Newsreader: WinVN 0.92.6+