Jump to content

Recommended Posts

Posted

Alguem me consegue verificar o que esta masl neste programa.. Eu tenho o Lazarus e ele está-m a dar um erro... 👍 n sei do que será.

Já agr alguem sabe qual o melhor programa de pascal pa utilizar no vista??

program Ficheiros_de_Registos;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

type registo = record
nome : string[15];
idade : integer;
end;

var fich1 : file of registo;
aluno : registo;
op : char;

function existeficheiro : boolean;
         begin
              assign(fich1, 'pessoas.dat')
              {$I-}
              reset (fich1) ; close (fich1);
              {$I+}
              existeficheiro := (IoResult=0);
         end;
procedure menu;

Begin
	writeln('Menu');
	writeln('Introduzir registos -> 1');
	writeln('Listar registos -> 2');
	writeln('Consultar e alterar -> 3');
	writeln('Terminar o programa -> 0');
	write('Tecle a sua escolha ->');
	repeat
	      readln(op);
	until
		op in['0'..'3']
end;
procedure Introduzir;
var C, N : Integer;

       Begin

            writeln('Introduzir registos');
            if exiteficheiro then
               reset (fich1);
            else
                rewrite (fich1);
            write ('Quantos registos?');
            readln(n);
            for c:=1 to N do
                begin
                     write('Nome: ');
                     readln(aluno.nome);
                     write('Idade: ');
                     readln(aluno.idade);
                     seek (fich1.filesize(fich1));
                     write(fich1, aluno);
                end;
                close(fich1);
       end;

procedure listar;
          begin
               clrscr;
               if not exiteficheiro then
                  begin
                       writeln('Ficheiro inexistente');
                       write('Tecle ENTER para menu');
                       repeat until readkey = #13;
                  end;
               else
               begin
                    reset(fich1);
                    writeln('Listar registos');
                    write('Registos no ficheiro: ');
                    writeln(filesize(fich1));
                    writeln;
                    while not eof (fich1) do
                          begin
                               read(fich1, aluno);
                               write(aluno.nome:15);
                               write(aluno.idade:4);
                               writeln;
                          end;
                          close (fich1);
                          writeln;
                          writeln('Tecle ENTER para menu');
                          repeat until readkey =#13;
               end;
               close(fich1);
          end;

procedure consultar
var n:integer; k:char;

    begin
         clrscr;
         if not existeficheiro then
         begin
              writeln('Ficheiro inesistente');
              write('Tecle ENTRE para menu');
              repeat until readkey =#13;
         end;
         else
         begin
              reset (fich1);
              writeln('Consultar e alterar registo');
              repeat
                    write('Nº do registo a consultar ');
                    writeln('entre 1 e ',filesize(fich1));
                    read(N);
              until (N>0) and (N<=filesize(fich1));
              seek (fich1, n-1);
              read (fich1, aluno);
              writeln(aluno.nome:15, aluno.idade:4);
              write('Alterar os dados? S/N -> ');
              repeat
                    k:= upcase (readkey)
              until K in ['S' , 'N'];
              writeln;
              if K = 'S' then
                 begin
                      write('Escreva o novo nome:  ');
                      repeat
                            readln(aluno.nome);
                      until aluno.nome <> '';
                      write('Escreva a nova idade:  ');
                      seek (fich1, aluno);
                      write(fich1, aluno);
                 end;
                 close(fich1);
         end;
    end;

    begin
         repeat
               menu;
                    case op of
                         '1' : Introduzir;
                         '2' : Listar;
                         '3' : Consultar;
                    end;
         until op = '0'
    end.            

Agradecia ajuda o mais rapido possivel... Isto é pa um trabalho xD

Posted

E qual é o erro?

O que é importante é mostrares o erro, despejar o código não ajuda muito.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Posted

function existeficheiro : boolean;

        begin

              assign(fich1, 'pessoas.dat')

              {$I-}

              reset (fich1) ; close (fich1);

              {$I+}

              existeficheiro := (IoResult=0);

        end;

Está-m a dar um erro neste reset, esta é a mensagem que me aparece...

Projectoexemplo.lpr(25,15) Fatal: Syntax error, ";" expected but "identifier RESET" found

Posted

O erro diz tudo:

- erro de sintaxe

- era esperado um ; mas foi encontrado o identificador RESET

- linha 25, coluna 15

Ora, se foi encontrado RESET quando era esperado um ; , isso quer dizer que há um erro de sintaxe antes do RESET.

Se vires, antes do RESET tens assign(fich1, 'pessoas.dat') e é precisamente nessa linha que falta o ;.

Colocar assign(fich1, 'pessoas.dat'); e tudo estará OK.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Posted

http://www.portugal-a-programar.pt/guidelines/ 👍

1.1- Criar títulos relacionados com a própria dúvida do utilizador e nunca com frases do género "Please help meeeee...." ou "duvida urgentíssima", "Dúvida Urgente", "Dúvida", "ajuda num trabalho",entre outros. Esses títulos não são agradáveis por várias razões:

* não apelam à leitura do tópico, já que o utilizador ao ler aquilo simplesmente passa à frente (se repararem os tópicos com esses títulos são praticamente conversas de MSN com apenas dois intervenientes);

* não são agradáveis às pesquisas dos utilizadores que procuram informação;

cool stuffs to check.

http://blog.zxcoders.com//

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.