User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 373,561 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,872 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
May 22nd, 2005
Views: 4,171
This program searches the given txt file.And tells you how many there are. Just a reminder don't forget to put the searced txt file in C: or change it accordingly for more info or questions Silver.Lost.Raven@gmail.com have fun!!
pascal Syntax | 2 stars
  1.  
  2. {Full-Name:Lost-Raven}
  3. {A MENU DRIVEN PASCAL PROGRAM to find the sequencing char array which could be
  4. found in the rand.txt file which is in c:\ folder.For this program I have used
  5. arrays while loops if's repeat until's and case's everything is written in the
  6. program if its not working or if it gives a runtime error please check help(read
  7. known bugs).If you want more info on the program contact me by
  8.  If you want more info on me visit my website
  9. www.johnroach.edu.tc thanks for using my program.... }
  10. {
  11. ----------->Known bugs in this program:
  12.  
  13. 1-In some compilers maxint is not understood.we can write 13000 intead of it.I
  14. written it thinking it will work in your compiler.
  15.  
  16. 2-This program has been written with dev-pascal 1.9.2 so there may be some
  17. compiler issues i am not aware of.(I have tested this program in freepascal and
  18. in bloodshed dev-pascal worked smoothly in those).This program gives no syntax
  19. errors in the compilers above.
  20.  
  21. 3-Some writing in the output tend to go to the next sentence this is mostly
  22. caused of using small dos windows please use the full screen mode for better results.
  23.  
  24. }
  25.  
  26. Program HW3 (fdata,Output,Input);
  27.  
  28.  
  29. var
  30. i,t,r,c,z,m:integer;
  31. fdata : TEXT;
  32. a : array[1..maxint] of char;
  33. b:array[1..1000] of char;
  34. q,x,n,s:char;{the checking of the menu}
  35. sentinel:array[1..4] of boolean;
  36. choice:char;
  37.  
  38. procedure datatoarray;{as you may have understand this throws all of the rand file
  39. into a array}
  40.  
  41. begin
  42. z:=1;
  43. repeat
  44. read(fdata,a[z]);
  45.  
  46. z:=z+1;
  47. until(EOln(fdata)) ;
  48.  
  49. end;
  50. Procedure about;{Who wrote it?Why?Is there more i can see?}
  51.  
  52. begin
  53. writeln(' ');
  54. writeln(' About ');
  55. writeln('--------');
  56. writeln(' ');
  57. writeln(' This program has been written by John Roach');
  58. writeln(' ');
  59. writeln(' It is a program that can find the wanted sequence in the ');
  60. writeln(' ');
  61. writeln(' file rand.');
  62. writeln(' ');
  63. writeln(' For any questions comments or extra points please contact me');
  64. writeln(' ');
  65. writeln(' e-mail:Silver.Lost.Raven@gmail.com');
  66. writeln(' ');
  67. writeln(' Also for daily updates on Johns life please visit');
  68. writeln(' ');
  69. writeln(' http://www.johnroach.edu.tc ');
  70. writeln(' ');
  71. writeln(' !!!P.S!!!!THERE ARE NEW UPDATES ON MY SITE!!!');
  72. end;
  73. Procedure help;{Every program needs a help text }
  74. begin
  75. writeln('-');
  76. writeln(' ');
  77. writeln(' HELP');
  78. writeln('------');
  79. writeln(' ');
  80. writeln(' The Reasons Why Didn"t the program work');
  81. writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
  82. writeln(' ');
  83. writeln('1-)You may have entered too many variables to find');
  84. writeln(' ');
  85. writeln('Please notice that the max variables is 1000.');
  86. writeln(' ');
  87. writeln('2-)Your rand.txt file is not in C:\rand.txt please put it there');
  88. writeln(' ');
  89. writeln('3-)You may have forgotten to put a $ sign right after the last');
  90. writeln(' ');
  91. writeln('char you have entered.This mistake causes a runtime error.');
  92. writeln(' ');
  93. writeln('4-)Don"t forget you have to go step by step!!!!!!');
  94. writeln(' ');
  95. writeln('5-)Even tough this program is to be said to be bugless');
  96. writeln(' ');
  97. writeln('i may have missed something.(Its not likely)');
  98. writeln(' ');
  99. end;
  100. procedure menu;{standart issue menu}
  101. begin
  102. writeln('-');
  103. writeln(' ');
  104. writeln(' MENU');
  105. writeln('------');
  106. writeln('Press 1 to enter the sequence you are looking for ',n,s,q,x);
  107. writeln('Press 2 to see if we can find your sequence ');
  108. writeln('Press 3 to go to Help');
  109. writeln('Press 4 to go to About');
  110. writeln('Press 0 to EXIT');
  111. writeln(' ');
  112. end;
  113. procedure userinput;{geting the user input and defining it as an char array}
  114. begin
  115. i:=1;
  116. writeln('-');
  117. writeln(' ');
  118. writeln('Please enter the sequence you want to find. ');
  119. writeln('And remember not to exceed more than 1000 characters. ');
  120. writeln('If you have problems with the program please consult ');
  121. writeln('the help menu.');
  122. writeln('After you have finished inputing the sequence press $ then enter ');
  123. m:=1;
  124. repeat{repeats until end of line}
  125. read(b[i]);
  126. i:=i+1;
  127. until(eoln) ;
  128. if (b[m]=b[2]) then
  129. begin
  130. sentinel[3]:=true;
  131. sentinel[4]:=true;
  132. end;
  133. if (b[m]<>b[2]) then
  134. begin
  135. sentinel[2]:=false;
  136. sentinel[1]:=false;
  137. end;{ok its hard to
  138.   explain why i did this but i will try.this is for a
  139.   special condition for ele108 and such cases.because there is an extra e
  140.   in front one of them such as eele108 this gives a wrong
  141.   answer so i had to put a check on -procedure find- but later on
  142.   I tought what if the man inputs a double sequence such as
  143.   eele108 what if this is what the user is trying to find so this
  144.   that check}
  145. if i>1000 then {to stop warn people of the overflow!!!}
  146. begin
  147. writeln(' ');
  148. writeln('!!!!WARNING!!!!You have entered more than 1000 chars');
  149. writeln('My program was designed for a sequence shorter than');
  150. writeln('or equal to 1000 chars');
  151. writeln(' ');
  152. end; {end of if}
  153. writeln(' ');
  154. writeln(' ');
  155. end;{end of process userinput}
  156.  
  157. procedure find;{this is where the GOLD lies.This where we find the user inputed sequence!!!}
  158. begin
  159. m:=0;
  160. c:=-1;{because the while loop will increment the c the first time}
  161. r:=1;
  162. while r<>z do{z as you can see above z is the last index for the array a[] used}
  163. begin
  164.  
  165. repeat
  166. if b[t]=a[r] then {a is from text file and b is from input user}
  167. begin {increments both at the same time to check the next char}
  168. t:=t+1;
  169. r:=r+1;
  170. m:=t-1;
  171. if ((b[m]=a[r]) and (sentinel[1]=false) and (sentinel[2]=false) and (sentinel[3]=false) and (sentinel[4]=false) ) then begin c:=c+1;end;
  172. {I have explained why I have written this in -procedure userinput- this is the check
  173.   that I was talking about}
  174. end
  175. else
  176. begin
  177. t:=1; {if all of the b array wasn't equal till end of b we will have to re-check}
  178. r:=r+1;
  179. sentinel[1]:=false;{Again this is for the use of checking that i have explained in
  180.   -procedure userinput-}
  181.  
  182. end; {end of if}
  183.  
  184.  
  185. until ((b[t]='$') or (r=z));
  186. c:=c+1;
  187.  
  188. end;{end of while}
  189.  
  190. end;{end of procedure}
  191.  
  192. procedure dochoice;{the procedure that brings out the menu}
  193.  
  194. begin
  195. case choice of
  196.  
  197. '1': begin
  198. userinput;
  199. n:='-';{well actually made this one for fun :-) it writes ok next to the menu}
  200. s:='>';
  201. q:='O';
  202. x:='K';
  203. menu;
  204. end;
  205.  
  206. '2':begin
  207.  
  208. find;
  209. writeln('This is how many of your sequence is in the rand.txt file ' ,c);
  210. If c=0 then writeln('So basicly you have used the program wrong or there is no such sequencing char.') ;
  211.  
  212. n:=' ';{just to clean up the menu}
  213. s:=' ';
  214. q:=' ';
  215. x:=' ';
  216. menu;
  217.  
  218. end;
  219. '3':begin
  220. help;
  221. menu;
  222. end;
  223. '4':begin
  224. about;
  225. menu;
  226. end;
  227. end;{end of case statement}
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. end; {end of dochoice}
  237. BEGIN
  238.  
  239.  
  240. assign( fdata, 'C:\rand.txt' );{this is where you specify the address}
  241. reset(fdata );
  242.  
  243.  
  244. datatoarray;
  245.  
  246. n:=' ';
  247. s:=' ';
  248. q:=' ';
  249. x:=' ';
  250. menu;
  251.  
  252. repeat
  253. readln(choice);
  254. dochoice;
  255. until(choice='0');
  256.  
  257.  
  258. CLOSE( fdata );
  259.  
  260.  
  261.  
  262. END. {end of program}
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 7:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC