Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.49 KB | None | 0 0
  1. program task4;
  2.  
  3. // Открытие файла
  4. procedure OpenFile(var f: text; fname: string);
  5. var
  6.   fileName: string;
  7. begin
  8.   // write('Введите имя файла: ');
  9.   // Readln(fileName);
  10.   assign(f, fname);
  11.   reset(f);
  12. end;
  13.  
  14. // Вывод строк файла на экран. Перед строкой отображается еѐ
  15. // номер в файле
  16. procedure PrintFile(var f: text);
  17.  
  18. var
  19.   ch: char;
  20.   num, pos: integer; // num – номер строки в файле
  21.  
  22. begin
  23.   num := 1;
  24.   write(num, ' ');
  25.   reset(f);
  26.   while not eof(f) do
  27.   begin
  28.     Read(f, ch);
  29.     Dec(pos);
  30.     if ch = #10 then
  31.       continue;
  32.     if ch = #13 then // переходим к следующей строке
  33.     begin
  34.       writeln;
  35.       Inc(num);
  36.       write(num, ' ');
  37.       continue;
  38.     end;
  39.     write(ch);
  40.   end;
  41. end;
  42.  
  43. procedure copyLettersInOutFile(var inf: text; var outf: text);
  44.  
  45. var
  46.   symbol: char;
  47. begin
  48.   assign(outf, 'out.txt');
  49.   rewrite(outf);
  50.   symbol := 'a';
  51.   while not eof(inf) do
  52.   begin
  53.     Read(inf, symbol);
  54.     if symbol = #10 then
  55.       continue;
  56.     if symbol = #13 then
  57.     begin
  58.       Write(outf, #13);
  59.       continue;
  60.     end;
  61.     if not(symbol in ['0' .. '9']) then
  62.       Write(outf, symbol);
  63.   end;
  64.   close(outf);
  65. end;
  66.  
  67. var
  68.   inFile, outFile: text;
  69.   cancel: integer;
  70.  
  71. begin
  72.  
  73.   OpenFile(inFile, 'in.txt');
  74.   copyLettersInOutFile(inFile, outFile);
  75.   PrintFile(outFile);
  76.   close(inFile);
  77.   read(cancel);
  78.  
  79. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement