// Entrada de numeros de DNI a un string
program numeros;
uses Crt;
const NoDNI = '********';
var DNI: string;
function LeerDNI: string;
var s: string;
ch: char;
n: integer;
IOerror: integer;
begin
n := 1; // Inicializar n a un valor <> 0
s := '';
write('Introduzca los 8 numeros del DNI, porfa [S para salir]: ');
repeat // Ir leyendo los digitos uno a uno
{$I-}
ch := ReadKey;
{$I+}
IOError := IoResult;
if IOError = 0 then // Caracter recibido correctamente
begin
if (ch >= '0') and (ch <= '9') then // Digito Ok
begin
s := s + ch; // Añadirlo a los anteriores
write(ch); // y ponerlo en la pantalla
end;
end else
ch := #0; // Esto es una seguridad un tanto paranoica
until (Length(s) = 8) or (UpCase(ch) = 'S');
writeln;
if Length(s) = 8 then // Ha terminado el bucle repeat con un DNI de 8 digitos
LeerDNI := s
else // Ha terminado con la tecla 'S'
LeerDNI := NoDNI;
end;
begin
clrscr;
repeat
DNI := LeerDNI;
if DNI <> NoDNI then
begin
writeln('El DNI es ', DNI);
writeln;
readkey;
end;
until DNI = NoDNI;
writeln('Fin de Programa. Vuelva cuando quiera.');
ReadKey;
end.