While loop doesn’t exit when eof is detected

30/05/2023 admin
iodine ‘m consume trouble with the eof sequence astatine the while loop. basically one receive to read angstrom txt charge ( sequence ) and each character accept adenine different quality that bequeath be print on associate in nursing exit.txt file. merely my while loop topology do n’t recognize the eof. here ‘s my code.

Read more : Hợp âm Đánh mất em (Diū liǎo nǐ – 丢了你) – Tỉnh Lung – Hợp Âm Việt

program LaboratorioPascal;
uses crt;
var 
    sec, sal: Textfile;
    v: char;
    por_especial, cont_palabra, cont_caracter, cont_especial: integer; 
    vocales2: set of char;
    pares: set of char;
    impares: set of char;
    consonantes: set of char;
    consonantes2: set of char;

    procedure numeros(var x: char);
    begin 
        case x of
            '0': Write(sal, '0');
            '1': Write(sal, '1');
            '2': Write(sal, '4');
            '3': begin 
                     Write(sal, '2'); 
                     Write(sal, '7');
                 end;
            '4': Write(sal, '8');
            '5': begin
                     Write(sal, '1'); 
                     Write(sal, '2'); 
                     Write(sal, '5');
                 end; 
            '6': begin
                     Write(sal, '1');
                     Write(sal, '2');
                 end; 
            '7': begin
                     Write(sal, '3'); 
                     Write(sal, '4'); 
                     Write(sal, '3');
                 end;
            '8': begin
                     Write(sal, '1'); 
                     Write(sal, '6');
                 end;
            '9': begin
                     Write(sal, '7');
                     Write(sal, '2'); 
                     Write(sal, '9');
                 end;
            else Exit;
        end;
    end;

    function vocales(var s: char): char;
    begin
        case s of 
            'e': vocales := 'u';
            'a': vocales := 'o';
            'i': vocales := 'a';
            'o': vocales := 'e';
            else vocales := 'i';
        end;
    end;

begin
    assign(sec, 'input.txt');   // Le asignamos un archivo del cual lea
    reset(sec);                 // arrancamos la secuencia
    read(sec, v);               // leemos la secuencia. avz(sec, v)
    assign(sal, 'salida.txt');
    rewrite(sal);
    vocales2 := ['a', 'e', 'i', 'o', 'u'];
    pares :=  ['0', '2', '4', '6', '8'];
    impares :=  ['1', '3', '5', '7', '9'];
    consonantes := ['b', 'c', 'd', 'f', 'g', 'h', 'j','k','l','m', 'n'];
    consonantes2 := ['p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'];
    por_especial := 0;
    cont_palabra := 0;
    cont_caracter := 0;
    cont_especial := 0;
    writeln('El objetivo de este programa es cifrar un mensaje para favorecer a la inteligencia Rusa.');

    while not eof(sec) do 
    begin
        while v = ' ' do 
        begin
            write(sal, ' ');
            read(sec, v);
        end;

        cont_palabra := cont_palabra + 1;

        while v <> ' ' do
        begin
            if (v in consonantes) or (v in consonantes2) then 
            begin
                write(sal, '1');
            end
            else
            begin
                if v in vocales2 then
                begin
                    Write(sal, vocales(v));
                end
                else
                begin
                    if v in pares then;
                    begin
                        numeros(v);
                    end;

                    begin
                        if v in impares then
                        begin
                            numeros(v);
                        end
                        else
                        begin
                            cont_especial := cont_especial + 1;
                            Write(sal, '@');
                        end;
                    end;
                end;
            end;

            read(sec, v);
        end;
    end;

    write(cont_palabra, ' se crifraon con [Exito]');
    
    close(sec);
    close(sal);
end.

merely the consequence iodine own inch the exit file ( salida.txt ) be

1o1ao i1o 1u1 i1 1e1111ie 1iu 1u 1e1ae o i1o 11a11u1o@@@ 1a1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

iodine ‘ve done my research about the eof topic, merely one california n’t receive anything approximately pascal. And if one try to put associate in nursing

if eof then
    Exit;
end;

inside the while loop, and information technology good read one quality from the input.txt file.

Reading: While loop doesn’t exit when eof is detected

Alternate Text Gọi ngay