Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
need help in searching sequence file or text file... Posted by JapRax on 19 Sept 2002 at 5:28 AM
hii...i need some help in doing searching in text file.here are my problem...
i have to make a search procedure for my assignment:
i've only have to use sequential file/ text file, i cannot use arrays or even records.

A program is required to search for a requested item from a sequential file. the program must locate the item and report how many records the program searched through to locate the item.

each record is made up of the following fields
Vehicle make
vehicle model
year of manufacture
registration number

the program must
*Let user select which field to search for
*Let the user enter the value to search for
i have succesfuly made the program, but in my seach fields i cannotkeep seaching if i have the same input

here is my search procedure (say i want to search in the vehicle make fields)
found:=false
write('Enter The vihecle make ?');
readln(make);
repeat
readln(myfilename,make);
readln(..........,model);
r.................,year);
r.................,number);
found := search = make
until eof(myfilename) or found;
if found ........

in the actual file
there are two toyota
with my seach above i've only able to show the first one. not the second one.... i need some help here.....
how can i make it to seach the whole file then afterward display the result
if some one can help me i would like to ask you to be more specific and clear.... i'm really new with this things. Providing some example would be great full ....

thank you very much for your time....!!!






Report
Re: need help in searching sequence file or text file... Posted by weedsmoka on 19 Sept 2002 at 8:32 AM
begin
     found:=false 
     write('Enter The vihecle make ?'); 
     readln(make); 
     repeat 
           readln(myfilename,make); 
           readln(..........,model); 
           r.................,year); 
           r.................,number); 
           found := search = make 
     until eof(myfilename) or found; <----- this is why your procedure 
     if found ........                      stops when finding the 1st 
end.                                        toyota - remove the 
                                            "or found" and put the 
                                            "if found...." inside the 
                                             loop  
[/code]

here is my version:

begin
     write('Enter The vihecle make ?'); 
     readln(make); 
     repeat 
           readln(myfilename,make); 
           readln(..........,model); 
           r.................,year); 
           r.................,number); 
            
           if search = make then .........
     until eof(myfilename); 
end.                                  
Report
Re: need help in searching sequence file or text file... Posted by weedsmoka on 19 Sept 2002 at 8:35 AM
and another thing. line 3 - "readln(search);" instead of "readln(make);"
Report
Re: need help in searching sequence file or text file... Posted by JapRax on 19 Sept 2002 at 4:28 PM
: and another thing. line 3 - "readln(search);" instead of "readln(make);"
:
***********************************************************************
firstly thankyou for replying my msg.....
yeah i mistype that readln(seach) things....!!!

I have typed my program so that you can have look at it
but....the search procedure i haven't type all of them,i typed only one field.

=================================================
Program Assignment;
var make, model, reg, seach : string[20];
number, year, count : integer;
test : text;
found : boolean;

procedure filewrite;
begin
rewrite(test);
writeln('How many vehicle do you wish to enter ?');
readln(Number);
for count := 1 to number do
begin
Write('Enter the vehicle make ?');
readln(make);
write('Enter the Vehicle model ?');
readln(model);
write('Enter the year of manufacture of the car ?');
readln(year);
write('Enter the registration number of the car ?');
readln(reg);
writeln(test,make);
writeln(test,model);
writeln(test,year);
writeln(test,reg);
end;
close(test)
end;


procedure seachmake;

begin
Writeln('Seaching the make of the car');
assign(test,'test.txt');
reset(test);
found := false;
write('Enter the make of the car');
readln(seach);
repeat
readln(test,make);
readln(test,model);
readln(test,year);
readln(test,reg);
found := seach = make
until eof(test) or found;
if found then
writeln('The car model is ', model,' The year manufacture of the car ',year,' The registration of the car is ',reg)

else writeln('No Such car');
close(test)
end;

begin{main program}
assign(test, 'test.txt');
filewrite;
seachmake;
readln
end.

====================================================
the filewrite procedure aren't that important......
the things that make me confuse is the search procedure.
i cannot show both of the result if i have two source.....
say at the begining i put toyota twice in the make fields...
if i seach using the seach above, it will only came up with the first toyota that i typed in.......
please show me where did i do wrong....
thank you for your time

best of all,
Japrax

Report
Re: need help in searching sequence file or text file... Posted by weedsmoka on 19 Sept 2002 at 8:03 PM
i already explained your mistake, you must have missed the message or something...
http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=140108&Setting=A9999F0001

in your code the repeat lop ended like this:

until eof(test) or found;

what happens in your program is that the repeat loop stops as soon as
a matching car was found.

and again here is the correct procedure:

procedure seachmake;
begin
     Writeln('Seaching the make of the car');
     assign(test,'test.txt');
     reset(test);
     found := false;
     write('Enter the make of the car');
     readln(seach);
     repeat
           readln(test,make);
           readln(test,model);
           readln(test,year);
           readln(test,reg);
           found := seach = make;
           writeln('The car model is ', model,' The year manufacture of he car ' year,' The registration of the car is ',reg);

     until eof(test);
     if not found then writeln('No Such car');
     close(test)
end;


Report
Re: need help in searching sequence file or text file... Posted by JapRax on 19 Sept 2002 at 8:28 PM
: i already explained your mistake, you must have missed the message or something...
: http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=140108&Setting=A9999F0001
:
: in your code the repeat lop ended like this:
:
: until eof(test) or found;
:
: what happens in your program is that the repeat loop stops as soon as
: a matching car was found.
:
: and again here is the correct procedure:
:
:
: procedure seachmake;
: begin
:      Writeln('Seaching the make of the car');
:      assign(test,'test.txt');
:      reset(test);
:      found := false;
:      write('Enter the make of the car');
:      readln(seach);
:      repeat
:            readln(test,make);
:            readln(test,model);
:            readln(test,year);
:            readln(test,reg);
:            found := seach = make;
:            writeln('The car model is ', model,' The year manufacture of he car ' year,' The registration of the car is ',reg);
: 
:      until eof(test);
:      if not found then writeln('No Such car');
:      close(test)
: end;
: 

:
:
***********************************************************************

i have try your suggestion but it did't solve my problem..... and i also have try your code[above] it's the same.... when you run it... it goes o'k.... but when u do the seach things...the result came up all.... say i put... toyota, honda, toyota{again}... then when i do the search procedure it shows all of them..... even the honda...!!!
and with this assignment i have to show in which field the answer located..... any idea of that.....? say i want to seach honda..... the output = honda is the 2nd car....

thanks for answering my msg....
i hope i don't make you confuse.....

best regards...
Japrax
Report
Re: need help in searching sequence file or text file... Posted by weedsmoka on 19 Sept 2002 at 10:02 PM
ok.. try this one.. now it should work (i think)

procedure seachmake;
begin
     Writeln('Seaching the make of the car');
     assign(test,'test.txt');
     reset(test);
     found := false;
     write('Enter the make of the car');
     readln(seach);
     found:=false;
     repeat
           readln(test,make);
           readln(test,model);
           readln(test,year);
           readln(test,reg);
           if seach = make then
           begin
                writeln('The car model is ', model,' The year manufacture of he car ' year,' The registration of the car is ',reg);
                found:=true;
           end;
 
     until eof(test);
     if not found then writeln('No Such car');
     close(test)
end;
 




Report
Re: need help in searching sequence file or text file... Posted by JapRax on 20 Sept 2002 at 1:16 AM
This message was edited by JapRax at 2002-9-20 1:52:20

: ok.. try this one.. now it should work (i think)
:
:
: procedure seachmake;
: begin
:      Writeln('Seaching the make of the car');
:      assign(test,'test.txt');
:      reset(test);
:      found := false;
:      write('Enter the make of the car');
:      readln(seach);
:      found:=false;
:      repeat
:            readln(test,make);
:            readln(test,model);
:            readln(test,year);
:            readln(test,reg);
:            if seach = make then
:            begin
:                 writeln('The car model is ', model,' The year manufacture of he car ' year,' The registration of the car is ',reg);
:                 found:=true;
:            end;
:  
:      until eof(test);
:      if not found then writeln('No Such car');
:      close(test)
: end;
:  
: 

:
:
:
: *********************************************************************

damn... you are a life saver...... thank you very much for your help...
your second code really helpfull, now i just have to make the pseudo code for it.....
if you don't mind, i want to know what the'found = true' do to my program....? any explanation will do....hheheheheh
oh yah one more think....

how to show in pseudo code of
assign(test, 'test.txt');

o'k thanks again for your help..
god bless you and most of all god bless programmersheaven.com
c..ya



Report
Re: need help in searching sequence file or text file... Posted by weedsmoka on 20 Sept 2002 at 2:01 AM
: damn... you are a life saver...... thank you very much for your help...
: your second code really helpfull, now i just have to make the pseudo code for it.....
: if you don't mind, i want to know what the'found = true' do to my program....? any explanation will do....hheheheheh
: oh yah one more think....
:
: how to show in pseudo code of
: assign(test, 'test.txt');
:
: o'k thanks again for your help..
: god bless you and most of all god bless programmersheaven.com
: c..ya


the "found:=true " is needed for:
"if not found then writeln('No Such car')"

umm pseudo code of "assign"..
i would do 1 of 2:
1:leave it as it is: "assign test,test.txt"
or
2:simply remove the assign and reset and close and on read do: read file,variable






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.