How to improve my programm in Pascal?

Reply

Join Date: Sep 2009
Posts: 1
Reputation: yozuca is an unknown quantity at this point 
Solved Threads: 0
yozuca yozuca is offline Offline
Newbie Poster

How to improve my programm in Pascal?

 
-1
  #1
Sep 16th, 2009
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;
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 828
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: How to improve my programm in Pascal?

 
0
  #2
Sep 16th, 2009
See the helpfile for the function Pos(). It will allow you to search for a substring.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 444
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is online now Online
Posting Pro in Training

Re: How to improve my programm in Pascal?

 
1
  #3
Sep 17th, 2009
you can use records to store the members data
like my code
  1.  
  2. {
  3. The DATA:
  4. 20081231 Betty 03/09/1978
  5.  
  6. The programm
  7. }
  8. program solution;
  9.  
  10. type Tmember = record
  11. id:longint;
  12. name:string;
  13. day:1..31;
  14. month:1..12;
  15. year:1900..3000;
  16. end;
  17.  
  18.  
  19. var infile:file of Tmember;
  20. infilename:string;
  21. someone:Tmember;
  22. searching:boolean;
  23. idn:longint;
  24.  
  25.  
  26. begin
  27. infilename:='C:\myfile.dat';
  28. write('Member ID > ');
  29. readln(idn);
  30. searching:=false;
  31. assign(infile,infilename);
  32. reset(infile);
  33. while not eof(infile) do begin
  34. read(infile,someone);
  35. if idn=someone.id then begin
  36. writeln('Name:',someone.name);
  37. writeln('Date of birth: ',someone.day,'-',someone.month,'-',someone.year);
  38. searching:=true;
  39. end;
  40. end;
  41. if searching=false then
  42. writeln(someone.id,' cannot be found.');
  43. close(infile)
  44. 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...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 444
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is online now Online
Posting Pro in Training

Re: How to improve my programm in Pascal?

 
0
  #4
Sep 20th, 2009
I think I forget about writting a record to a file.....fixed.....
  1.  
  2. {full commented version created by FlamingClaw 2009}
  3. program solution;
  4.  
  5. type Tmember = record
  6. id:longint;
  7. name:string;
  8. day:1..31;
  9. month:1..12;
  10. year:1900..3000;
  11. end;
  12.  
  13.  
  14. var infile:file of Tmember; {this file can contain records only...}
  15. infilename:string; {stores the file's name ,path,and extension}
  16. someone,base:Tmember; {two records,someone for read in,base for write in}
  17. searching:boolean; {checking search,done it or not...}
  18. idn:longint; {we search by id,and its type is longint same as in the record's field}
  19.  
  20. {here begins the main program}
  21. begin
  22. {the file named myfile.dat and placed to the C:\ drive}
  23. infilename:='C:\myfile.dat';
  24. write('Member ID > ');
  25. {here catch the answer of the user}
  26. readln(idn);
  27. {searching is set to false}
  28. searching:=false;
  29. {assign the file var to a file,that is set to infilename }
  30. assign(infile,infilename);
  31. {create the data file,or if it is exists then delete its contents!}
  32. rewrite(infile);
  33. {fill the record's fields with these data:
  34.   20081231 Betty 03/09/1978 }
  35. with (base) do begin
  36. id:=20081231;
  37. name:='Betty';
  38. day:=03;
  39. month:=09;
  40. year:=1978;
  41. end;
  42. {first write the data file contents}
  43. write(infile,base);
  44. {file opening for reading...}
  45. reset(infile);
  46. {loop will over and over till we reach the end of the file}
  47. while not eof(infile) do begin
  48. {read one record,by round}
  49. read(infile,someone);
  50. {if the catched answer is equal to the readed record' id field then}
  51. if idn=someone.id then begin
  52. {write out the results to the screen,used by the record}
  53. writeln('Name:',someone.name);
  54. writeln('Date of birth: ',someone.day,'-',someone.month,'-',someone.year);
  55. {and the searching was success,everybody happy !}
  56. searching:=true;
  57. end;
  58. end;
  59. {if there were not success the loop then,search is stay false}
  60. if searching=false then
  61. {and notify the user...}
  62. writeln(someone.id,' cannot be found.');
  63. {it is not matter that the process was success or not close the file}
  64. close(infile);
  65. readln;{waits for pressing the enter button}
  66. 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...
Reply With Quote Quick reply to this message  
Reply

Tags
pascal

Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC