| | |
How to improve my programm in Pascal?
![]() |
•
•
Join Date: Sep 2009
Posts: 1
Reputation:
Solved Threads: 0
This is my programm which is to search in the data file.
I cannot search the data with key words/character but only the full words.
How can I correct my programm to become searching in key words/character?
The DATA:
20081231 Betty 03/09/1978
The programm
begin
write('Member ID > ');
readln(tid);
searching:=false;
assign(infile,infilename);
reset(infile);
while not eof(infile) do begin
readln(infile,id,na,bdy,bdm,bdd);
if id=tid then begin
writeln('Name:',na);
writeln('Date of birth: ',bdy,'-',bdm,'-',bdd);
searching:=true;
end;
end;
if searching=false then
writeln(tid,' cannot be found.');
close(infile)
end;
I cannot search the data with key words/character but only the full words.
How can I correct my programm to become searching in key words/character?
The DATA:
20081231 Betty 03/09/1978
The programm
begin
write('Member ID > ');
readln(tid);
searching:=false;
assign(infile,infilename);
reset(infile);
while not eof(infile) do begin
readln(infile,id,na,bdy,bdm,bdd);
if id=tid then begin
writeln('Name:',na);
writeln('Date of birth: ',bdy,'-',bdm,'-',bdd);
searching:=true;
end;
end;
if searching=false then
writeln(tid,' cannot be found.');
close(infile)
end;
you can use records to store the members data
like my code
of course you can search any elements of the record in the file.
like my code
pascal Syntax (Toggle Plain Text)
{ The DATA: 20081231 Betty 03/09/1978 The programm } program solution; type Tmember = record id:longint; name:string; day:1..31; month:1..12; year:1900..3000; end; var infile:file of Tmember; infilename:string; someone:Tmember; searching:boolean; idn:longint; begin infilename:='C:\myfile.dat'; write('Member ID > '); readln(idn); searching:=false; assign(infile,infilename); reset(infile); while not eof(infile) do begin read(infile,someone); if idn=someone.id then begin writeln('Name:',someone.name); writeln('Date of birth: ',someone.day,'-',someone.month,'-',someone.year); searching:=true; end; end; if searching=false then writeln(someone.id,' cannot be found.'); close(infile) end.
of course you can search any elements of the record in the file.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
I think I forget about writting a record to a file.....fixed.....
pascal Syntax (Toggle Plain Text)
{full commented version created by FlamingClaw 2009} program solution; type Tmember = record id:longint; name:string; day:1..31; month:1..12; year:1900..3000; end; var infile:file of Tmember; {this file can contain records only...} infilename:string; {stores the file's name ,path,and extension} someone,base:Tmember; {two records,someone for read in,base for write in} searching:boolean; {checking search,done it or not...} idn:longint; {we search by id,and its type is longint same as in the record's field} {here begins the main program} begin {the file named myfile.dat and placed to the C:\ drive} infilename:='C:\myfile.dat'; write('Member ID > '); {here catch the answer of the user} readln(idn); {searching is set to false} searching:=false; {assign the file var to a file,that is set to infilename } assign(infile,infilename); {create the data file,or if it is exists then delete its contents!} rewrite(infile); {fill the record's fields with these data: 20081231 Betty 03/09/1978 } with (base) do begin id:=20081231; name:='Betty'; day:=03; month:=09; year:=1978; end; {first write the data file contents} write(infile,base); {file opening for reading...} reset(infile); {loop will over and over till we reach the end of the file} while not eof(infile) do begin {read one record,by round} read(infile,someone); {if the catched answer is equal to the readed record' id field then} if idn=someone.id then begin {write out the results to the screen,used by the record} writeln('Name:',someone.name); writeln('Date of birth: ',someone.day,'-',someone.month,'-',someone.year); {and the searching was success,everybody happy !} searching:=true; end; end; {if there were not success the loop then,search is stay false} if searching=false then {and notify the user...} writeln(someone.id,' cannot be found.'); {it is not matter that the process was success or not close the file} close(infile); readln;{waits for pressing the enter button} end. {and here the end of the program}
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
![]() |
Similar Threads
- What program language should a beginner use? (IT Professionals' Lounge)
- Pascal random numbers are not random (Pascal and Delphi)
- Clean Your Prefetch to Improve Performance (Windows tips 'n' tweaks)
- Pascal games (Pascal and Delphi)
- Pascal Help (Pascal and Delphi)
- Turbo pascal homework (Pascal and Delphi)
- Pascal starter. (Pascal and Delphi)
- Pseudo-Pascal Question: Need Help!! (Pascal and Delphi)
- Modify Settings to Improve Performance (Windows tips 'n' tweaks)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: question on TFileStream (Inno Setup)
- Next Thread: Delphi programs not responding when run outside of IDE
| Thread Tools | Search this Thread |






