L
L
leo12322020-12-16 21:56:34
Delphi
leo1232, 2020-12-16 21:56:34

For what reason after writing the text. Does the program terminate instead of displaying the result?

For what reason after writing the text. Instead of displaying the result, the program terminates.
The essence of the program: The program must perform the following actions: organize line-by-line reading of data from a file, increase the code of each character of the line by 1, write the line to the output file, and decrypt the encrypted file in the same way. Each action is made out as a subroutine. The main program implements only the dialog loop of interaction with the user.

program Project21;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

var
  f1, f2: Text;
  N1, N2: string;
  ED: byte;
// Расшифровка

function Encode_String(S: string): string;
var
  i, L: byte;
begin
  L := Length(S);
  for i := 1 to L do
    S[i] := Chr(Ord(S[i]) + 1);
  Encode_String := S; // или Result := S;
end;
//Шифровка

function Decode_String(S: string): string;
var
  i, L: byte;
  S1: string;
begin
  S1 := '';
  L := Length(S);
  for i := 1 to L do
    S1 := S1 + Chr(Ord(S[i]) - 1);
  Decode_String := S1;
end;

procedure Encode_File(Nm1, Nm2: string);
var
  S: string;
begin
  Assign(f1, Nm1);
  Reset(f1);
  Assign(f2, Nm2);
  Rewrite(f2);
  repeat
    Readln(f1, S);
    Writeln(f2, Encode_String(S));
  until EoF(f1);
  Close(f1);
  Close(f2);
end;

procedure Decode_File(Nm1, Nm2: string);
var
  S: string;
begin
  Assign(f1, Nm1);
  Reset(f1);
  Assign(f2, Nm2);
  Rewrite(f2);
  repeat
    Readln(f1, S);
    Writeln(f2, Decode_String(S));
  until EoF(f1);
  Close(f1);
  Close(f2);
end;

begin
  repeat
    Writeln('Choose the action: 1 - encode');
    Writeln(' 2 - decode');
    Writeln(' 0 - quit');
    Readln(ED);
    case ED of
      1:
        begin
          write('Initial file name (full path): ');
          readln(N1);
          write('Encoded file name (full path): ');
          readln(N2);
        end;
      2:
        begin
          write('Encoded file name (full path): ');
          readln(N1);
          write('Decoded file name (full path): ');
          readln(N2);
          Decode_File(N1, N2);
        end;
    end;
    Writeln;
  until ED = 0;
end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2020-12-16
@leo1232

Because you do not call "encryption"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question