Board index » delphi » quick help on easy problem please

quick help on easy problem please

I want to write a small pascal program to read lines from a textfile
and output the same to an outputfile, omitting identical lines.

I has been a while since I programmed pascal, and I dont have any
manuals available, can you please find the error for me and Please both
Mail and Post o me.

I would be very grateful.

my code:

type filtyp = file of text;

var utfil, infil:filtyp;
indataold, indata:string[80];
begin
assign (utfil,'utfil.txt');
assign (infil,'infil.txt');
rewrite(utfil);
reset(infil);
while not eof(infil)
    do begin
   readln(infil,indata);
    if indata<>indataold then begin writeln(utfil,indata);
                                  oldindata=indata;
                                  end;

    end;

end.

and the error is:

D:\pascal>bin\tmtpc yes.p
TMT (R) Pascal Compiler Lite  v3.20. (Aug 05 1999)
(C) Copyright by TMT Development Corp. 1995, 1999. All rights reserved.
Free Version (restricted)

   readln(infil,indata);
         
Error: YES.P (line 12, col 11): TEXT file required

D:\pascal>

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

 

Re:quick help on easy problem please


Quote
> type filtyp = file of text;

> and the error is:

> D:\pascal>bin\tmtpc yes.p
> TMT (R) Pascal Compiler Lite  v3.20. (Aug 05 1999)
> (C) Copyright by TMT Development Corp. 1995, 1999. All rights reserved.
> Free Version (restricted)

>    readln(infil,indata);
>           &#8593;
> Error: YES.P (line 12, col 11): TEXT file required

     "text", by itself, is a type, often analogous to "PACKED FILE OF
char".  Thus your
type "filtyp" is equivalent to a "FILE OF FILE OF char".  You probably do
not need this
type definition, and can simply define your file variables as "VAR utfil :
text".

Bob Schor
Pascal Enthusiast

P.S. -- once you get the syntax correct, look closely at the logic of your
program.  Think about "uninitialized variables ...".

Re:quick help on easy problem please


Quote
> I want to write a small pascal program to read lines from a textfile
> and output the same to an outputfile, omitting identical lines.
> I has been a while since I programmed pascal, and I dont have any
> manuals available, can you please find the error for me and Please both
> Mail and Post o me.
> I would be very grateful.

   Well, you posted this in a Borland NG, but you're using TMT Pascal - a
conflict.  I don't know anything about TMT, but the error you're getting
below implies you shouldn't be using "file of text".  If this were a
Borland product, it should be Text.  I'm only guessing, but I would make
the following adjustments:
Quote
> my code:
> var utfil, infil : Text;
> indataold, indata : string[80];
> begin
> assign (utfil,'utfil.txt'); assign (infil,'infil.txt');
> rewrite(utfil); reset(infil);

  InDataOld := '';  { initialize... }
Quote
> while not eof(infil) do
    begin
>     readln(infil,indata);
>     if indata <> indataold then

        begin
          writeln(utfil,indata); InDataOld := indata
Quote
>       end;
>   end;

   Close (InFil); Close (UtFil);
   writeln ('End of program.')
Quote
> end.

> and the error is:

> D:\pascal>bin\tmtpc yes.p
> TMT (R) Pascal Compiler Lite  v3.20. (Aug 05 1999)
> (C) Copyright by TMT Development Corp. 1995, 1999. All rights reserved.
> Free Version (restricted)

>    readln(infil,indata);
>           &#8593;
> Error: YES.P (line 12, col 11): TEXT file required

> D:\pascal>

Re:quick help on easy problem please


In article <7rqkfr$56...@nnrp1.deja.com>, arcadepres...@hotmail.com
writes

Quote
>I want to write a small pascal program to read lines from a textfile
>and output the same to an outputfile, omitting identical lines.

Do you mean ADJACENT identical lines or ANY identical lines? If the
latter then your method won't work.

--
Marcus Morris - South Croydon, LONDON, UK (Mar...@ntos.demon.co.uk)

Re:quick help on easy problem please


Hello,

I've made a few changes to your code, because your programming-style is a
little hard for me to understand.

Her's my code :

var
oldfile, newfile : Text;
olddata, newdata : string[80];

begin
Assign (oldfile,'old.txt');
Assign (newfile,'new.txt');

Rewrite(newfile);
Reset(oldfile);

while (not Eof(oldfile)) do
  begin
     Readln(oldfile, newdata);
     if (newdata <> olddata) then
      begin
        Writeln(newfile, newdata);
        olddata := newdata;
      end; {if}
  end; {while}

Close(oldfile);
Close(newfile);

end;

This should do the job..

The problem was, that you can't declare a text-file with "file of", because
"file of" is used for declaring un-typed files (eg. random record - or
binary files). You need to declare it like this:

var
  MyFile : Text;

not like :

var
  MyFile : file of Text;

Than you must also remember to close your files (with "Close"
procedure),when done, or else it my corce a system crash (it happend two me
with TP7 and MS-DOS 6).

By, the way, for the interest - what compiler are you using ?

I hope this helps...

Regards,

Lennie De Villiers

Quote
arcadepres...@hotmail.com wrote in message <7rqkfr$56...@nnrp1.deja.com>...

|I want to write a small pascal program to read lines from a textfile
|and output the same to an outputfile, omitting identical lines.
|
|I has been a while since I programmed pascal, and I dont have any
|manuals available, can you please find the error for me and Please both
|Mail and Post o me.
|
|I would be very grateful.
|
|my code:
|
|type filtyp = file of text;
|
|var utfil, infil:filtyp;
|indataold, indata:string[80];
|begin
|assign (utfil,'utfil.txt');
|assign (infil,'infil.txt');
|rewrite(utfil);
|reset(infil);
|while not eof(infil)
|    do begin
|   readln(infil,indata);
|    if indata<>indataold then begin writeln(utfil,indata);
|                                  oldindata=indata;
|                                  end;
|
|    end;
|
|end.
|
|and the error is:
|
|D:\pascal>bin\tmtpc yes.p
|TMT (R) Pascal Compiler Lite  v3.20. (Aug 05 1999)
|(C) Copyright by TMT Development Corp. 1995, 1999. All rights reserved.
|Free Version (restricted)
|
|   readln(infil,indata);
|          &#8593;
|Error: YES.P (line 12, col 11): TEXT file required
|
|D:\pascal>
|
|
|Sent via Deja.com http://www.deja.com/
|Share what you know. Learn what you don't.

Other Threads