Fórum Problema ao Ler um arquivo #387377
27/09/2010
0
program Ed_Wilton_lista1;
uses crt;
{declaração de variaveis}
var
opc, i : integer;
arq: text;
resparq, resp, pos: char;
dir, wnome, wende: string;
nome, ende : array[0..10] of string;
{Inicio Procedures}
procedure error;
begin
writeln('Opcao Invalida! Tente Novamente.');
end;
procedure menu;
begin
writeln('ESCOLHA A OPCAO DESEJA NO MENU ABAIXO!');
writeln('**************************************');
writeln('* 1 - INSERIR *');
writeln('* 2 - REMOVER *');
writeln('* 3 - LISTAR *');
writeln('* 4 - PESQUISAR *');
writeln('* 5 - SAIR *');
writeln('**************************************');
write('>>');
end;
procedure GravaArquivo;
var textarq : string;
begin
assign(arq,dir);
if (resparq = 'L') then
Erase(arq);
Rewrite(arq);
for i:=0 to 9 do
begin
textarq := nome[i] + ',' + ende[i];
if textarq = ',' then
break;
write(arq, textarq);
writeln(arq, '');
end;
Close(arq);
Writeln('DADOS GRAVADO NO ARQUIVO COM SUCESSO');
end;
procedure LerArquivo;
begin
assign(arq,dir);
reset(arq);
i := 0;
while (not eof(arq)) do
begin
read(arq,nome[i]);
read(arq,ende[i]);
i := i + 1;
end;
Close(arq);
end;
procedure inserir;
begin
resp := 'S';
i := 0;
while (resp = 'S') do
begin
write('Digite um nome: ');
readln(wnome);
write('Digite o endereco: ');
readln(wende);
Repeat
write('Deseja inserir os dados no <i>nicio ou no <f>im do arquivo: ');
readln(pos);
pos := Chr(Ord(pos)-32);
if ((pos <> 'I') and (pos <> 'F')) then
error;
until(pos = 'I') or (pos = 'F');
case pos of
'I' : begin
writeln('Dados Inseridos no Inicio do Arquivo');
if (nome[0] <> '') then
begin
for i:=0 to 9 do
begin
if i <> 9 then
begin
nome[9-i] := nome[8-i];
ende[9-i] := ende[8-i];
end;
end;
end;
nome[0] := wnome;
ende[0] := wende;
end;
'F' : begin
writeln('Dados Inseridos no Fim do Arquivo');
if (nome[9] <> '') then
begin
for i:=0 to 8 do
begin
nome[i] := nome[1+i];
ende[i] := ende[1+i];
end;
end;
nome[9] := wnome;
ende[9] := wende;
end;
end;
repeat
write('Deseja cadastrar novamente <S>im ou <N>ao: ');
readln(resp);
resp := Chr(Ord(resp)-32);
if ((resp <> 'S') and (resp <> 'N')) then
error;
until(resp = 'S') or (resp = 'N');
if (resp = 'S') then
i := i + 1;
end;
end;
procedure listar;
begin
for i:=0 to 9 do
begin
write(i);
writeln(' ' + nome[i] + '-' + ende[i]);
end;
writeln('Fim da lista');
readkey;
end;
{sistema principal}
begin
dir := 'C:\Pinga\Ed_Wilton_Lista1.txt';
Repeat
write('Deseja <C>riar ou <L>er um arquivo: ');
readln(resparq);
resparq := Chr(Ord(resparq)-32);
if ((resparq <> 'C') and (resparq <> 'L')) then
error;
until(resparq = 'C') or (resparq = 'L');
if resparq = 'L' then
LerArquivo;
textbackground(green);
textcolor(yellow);
while (opc < 5) do
begin
clrscr;
opc := 0;
menu;
readln(opc);
case opc of
1 : begin
writeln('Inserir Dados');
inserir;
end;
2 : writeln('Remover');
3 : begin
writeln('Listar Dados');
listar;
end;
4 : writeln('Pesquisar');
5 : begin
GravaArquivo;
writeln('SISTEMA ENCERRADO.OBRIGADO!');
end;
end;
if (opc > 5) then
begin
Error;
readkey;
end;
end;
readkey;
end.
O codigo é esse quem puder ajudar eu agradeço muito.
obrigado
Deus Abençoe a todos
Wilton Júnior
Curtir tópico
+ 0Posts
27/09/2010
Marcos Iwazaki
Tipo se ele esta fazendo errado, se não faz nada, se da erro.Se esta fazendo errado... o que ele tafazendo e o que deveria fazer...
Olhando assim meio por cimaNão deveria ser Readln em vez de Read?
flw
Gostei + 0
28/09/2010
Wilton Júnior
obrigado
Gostei + 0
28/09/2010
Wilson Junior
Espero ter colaborado.
Gostei + 0
28/09/2010
Wilton Júnior
Gostei + 0
28/09/2010
Wilson Junior
procedure percorreArquivoTexto ( nomeDoArquivo: String );
var
arq: TextFile;
linha: String;
begin
AssignFile ( arq, nomeDoArquivo );
Reset ( arq );
ReadLn ( arq, linha );
while not Eof ( arq ) do
begin
{ Processe a linha lida aqui. }
{ Para particionar a linha lida em pedaços, use a função Copy. }
ReadLn ( arq, linha );
end;
CloseFile ( arq );
end;
Espero ter colaborado.
Gostei + 0
30/09/2010
Wilton Júnior
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)