WORD.PAS 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. program word;
  2. const
  3. MAX_KEY = 50;
  4. MAX_KEY_LEN = 10;
  5. type
  6. Line = string[128];
  7. KeyStr = string[MAX_KEY_LEN];
  8. var Keys : array [1..MAX_KEY] of KeyStr;
  9. Count : array [1..MAX_KEY] of integer;
  10. Filename : string[14];
  11. Line1 : Line;
  12. Num_Keys : integer;
  13. I : integer;
  14. Text_File : text;
  15. procedure ScanLine;
  16. var I, Ptr : integer;
  17. L : Line;
  18. begin
  19. for I := 1 to Num_Keys do begin
  20. L:= Line1; (* Make working copy *)
  21. Ptr := Pos(Keys[I],L);
  22. while Ptr > 0 do begin
  23. Count[I] := Count[I] + 1;
  24. Delete(L,Ptr,1);
  25. Ptr := Pos(Keys[I],L);
  26. end;
  27. end;
  28. end;
  29. begin
  30. write('Enter filename ');
  31. readln(Filename); writeln;
  32. write('Enter number of keywords ');
  33. readln(Num_Keys); writeln;
  34. for I := 1 to Num_Keys do begin
  35. Count[I] := 0; (* Zero counters *)
  36. write('Enter key # ',I,' ');
  37. readln(Keys[I]); writeln;
  38. end;
  39. writeln; writeln; writeln;
  40. Assign(Text_File,Filename);
  41. {$I-}
  42. Reset(Text_File);
  43. {$I+}
  44. while NOT Eof(Text_File) do begin
  45. readln(Text_File, Line1);
  46. writeln(Line1);
  47. ScanLine
  48. end;
  49. Close(Text_File);
  50. writeln;
  51. for I := 1 to Num_Keys do
  52. writeln(Keys[I],' counts ',Count[I],' times');
  53. end.
  54.