Leer una cadena de caracteres.
Publicado por Tate (5 intervenciones) el 06/12/2007 20:32:00
Mi problema es que no consigo leer una cadena de caracteres sin usar el tipo string. Lo estoy intentando con arrays de char. Esto es lo mas lejos que he llehago:
program leer_vector(Input,Output);
type
vector = packed array[1..10]of char;
var
i,j,lp :integer;
ok : boolean;
p : vector;
c:char;
begin
ok:=false;
repeat
for i:=1 to 10 do p[i]:='*';
writeln;
write('Introduzca la palabra a buscar: ');
i:=1;
repeat
read(c);
if c<>chr(10) then p[i]:=c;
i:=i+1;
until (c=chr(10)) or (i>10);
writeln;
if (p[2]='*') or (p[9+1]<>'*') then writeln('Palabra no valida!')
else begin
ok:=true;
end;
writeln;
writeln;
for i:=1 to 10 do write(p[i]);
until ok;
readln;
end.
No consigo aclararme con el comportamiento de este progrma. Si aguien me puede ayudar se lo agradeceria mucho.
program leer_vector(Input,Output);
type
vector = packed array[1..10]of char;
var
i,j,lp :integer;
ok : boolean;
p : vector;
c:char;
begin
ok:=false;
repeat
for i:=1 to 10 do p[i]:='*';
writeln;
write('Introduzca la palabra a buscar: ');
i:=1;
repeat
read(c);
if c<>chr(10) then p[i]:=c;
i:=i+1;
until (c=chr(10)) or (i>10);
writeln;
if (p[2]='*') or (p[9+1]<>'*') then writeln('Palabra no valida!')
else begin
ok:=true;
end;
writeln;
writeln;
for i:=1 to 10 do write(p[i]);
until ok;
readln;
end.
No consigo aclararme con el comportamiento de este progrma. Si aguien me puede ayudar se lo agradeceria mucho.
Valora esta pregunta


0