Board index » delphi » non text files in pascal

non text files in pascal

Quote
Ben Kelley wrote:

> I have a question.  Whenever I create a record file in pascal, I dont seem
> to be able to read it in a text editor.  I get garbage.  Any ideas?  For
> example....

> GymType = record of
>                 Name : Text;
>                 Locker : Integer;
>                 Age : Integer;
>               end;
> FileType  = File of GymType;

> Okay, now I run this program and store values in the file.  Then when I
> exit the program and look at the file created, I see garble dee gook.  How
> can I create a non text file, that is read by a program??
>         -tia  Ben

TEXT editor..any key words....
TEXT....to a text file you must write chars...
you must give the corresponding integer a char so that you may
write it.

]] Jason Chahal [[
       JESUS <>< rules...

 

Re:non text files in pascal


Quote
Ben Kelley wrote:

> I have a question.  Whenever I create a record file in pascal, I dont seem
> to be able to read it in a text editor.  I get garbage.  Any ideas?  For
> example....

> GymType = record of
>                 Name : Text;
>                 Locker : Integer;
>                 Age : Integer;
>               end;
> FileType  = File of GymType;

> Okay, now I run this program and store values in the file.  Then when I
> exit the program and look at the file created, I see garble dee gook.  How
> can I create a non text file, that is read by a program??
>         -tia  Ben

TEXT editor..any key words....
TEXT....to a text file you must write chars...
you must give the corresponding integer a char so that you may
write it.

]] Jason Chahal [[
        <>< rules...

Re:non text files in pascal


Quote
Ben Kelley wrote:

> I have a question.  Whenever I create a record file in pascal, I dont seem
> to be able to read it in a text editor.  I get garbage.  Any ideas?  For
> example....

> GymType = record of
>                 Name : Text;
>                 Locker : Integer;
>                 Age : Integer;
>               end;
> FileType  = File of GymType;

> Okay, now I run this program and store values in the file.  Then when I
> exit the program and look at the file created, I see garble dee gook.  How
> can I create a non text file, that is read by a program??
>         -tia  Ben

TEXT editor..any key words....
TEXT....to a text file you must write chars...
you must give the corresponding integer a char so that you may
write it.

]] Jason Chahal [[
       JESUS <>< rules...

Re:non text files in pascal


Quote
Ben Kelley wrote:

> I have a question.  Whenever I create a record file in pascal, I dont seem
> to be able to read it in a text editor.  I get garbage.  Any ideas?  For
> example....

> GymType = record of
>                 Name : Text;
>                 Locker : Integer;
>                 Age : Integer;
>               end;
> FileType  = File of GymType;

> Okay, now I run this program and store values in the file.  Then when I
> exit the program and look at the file created, I see garble dee gook.  How
> can I create a non text file, that is read by a program??
>         -tia  Ben

TEXT editor..any key words....
TEXT....to a text file you must write chars...
you must give the corresponding integer a char so that you may
write it.

]] Jason Chahal [[ Ben Kelley wrote:
       JESUS <>< rules...

Re:non text files in pascal


I have a question.  Whenever I create a record file in pascal, I dont seem
to be able to read it in a text editor.  I get garbage.  Any ideas?  For
example....

GymType = record of
                Name : Text;
                Locker : Integer;
                Age : Integer;
              end;
FileType  = File of GymType;

Okay, now I run this program and store values in the file.  Then when I
exit the program and look at the file created, I see garble dee gook.  How
can I create a non text file, that is read by a program??
        -tia  Ben

Re:non text files in pascal


In article <01bc51f5$47fe0b40$4d2a8acd@benjamik>, "Ben Kelley"

Quote
<mz...@tir.com> wrote:
>I have a question.  Whenever I create a record file in pascal, I dont seem
>to be able to read it in a text editor.  I get garbage.  Any ideas?  For
>example....

>GymType = record of
>                Name : Text;
>                Locker : Integer;
>                Age : Integer;
>              end;
>FileType  = File of GymType;

>Okay, now I run this program and store values in the file.  Then when I
>exit the program and look at the file created, I see garble dee gook.  How
>can I create a non text file, that is read by a program??
>        -tia  Ben

You have to use the same record to read it again
Henrik

Re:non text files in pascal


In article <01bc51f5$47fe0b40$4d2a8acd@benjamik>, "Ben Kelley"

Quote
<mz...@tir.com> wrote:
>I have a question.  Whenever I create a record file in pascal, I dont seem
>to be able to read it in a text editor.  I get garbage.  Any ideas?  For
>example....

>GymType = record of
>                Name : Text;
>                Locker : Integer;
>                Age : Integer;
>              end;
>FileType  = File of GymType;

>Okay, now I run this program and store values in the file.  Then when I
>exit the program and look at the file created, I see garble dee gook.  How
>can I create a non text file, that is read by a program??
>        -tia  Ben

You have to use the same record to read it again
HEnrik

Re:non text files in pascal


Quote
"Ben Kelley" <mz...@tir.com> wrote:
>I have a question.  Whenever I create a record file in pascal, I dont seem
>to be able to read it in a text editor.  I get garbage.  Any ideas?  For
>example....
>GymType = record of
>            Name : Text;

                   ^^^^^
I'm guessing you meant to type "String" here, but if this is what
you've actually got then you're really confused.

Quote
>            Locker : Integer;
>            Age : Integer;
>          end;
>FileType  = File of GymType;
>Okay, now I run this program and store values in the file.  Then when I
>exit the program and look at the file created, I see garble dee gook.  How
>can I create a non text file, that is read by a program??
>    -tia  Ben

When you create a "file of <some record type>" that is a BINARY file.
When you write out one of those records to the file any data in the
record is inserted into the file in its binary form and must be read
back in similar fashion.  If you want to be able to read the output in
a text editor, send it to the screen, or some other text mode usage,
you have treat the data accordingly.  In particular, the output file
must be of type Text and you must create your own output routine for
the record to write the fields as text:

GymType = record of
                Name : string;
                Locker : Integer;
                Age : Integer;
              end;

procedure WriteGymType( var F : text ; GymVar : GymType ) ;
(* assumes F has already been opened for writing *)
begin
  WriteLn( F, 'Name = ', Gymvar.Name ) ;
  WriteLn( F, 'Locker = ', Locker:3 ) ;  
  WriteLn( F, 'Age = ', Age:3 ) ;
end ;

var
  TheFile : Text ;
  Gym : GymType ;

begin
  with Gym do
  begin
    Name := 'Ben's Gym' ;
    Locker := 10 ;
    Age := 30 ;
  end ;
  Assign( TheFile, 'OUTPUT.DAT' ) ;
  Reset( TheFile ) ;
  WriteGymType( TheFile, Gym ) ;
  Close( TheFile ) ;
end .  

If this isn't clear or isn't what you're after, Email me with some
more details and I'll go further with you.

Regards,

Stephen Posey
slpo...@Concentric.net

Re:non text files in pascal


Quote
> TEXT editor..any key words....
> TEXT....to a text file you must write chars...
> you must give the corresponding integer a char so that you may
> write it.

I dont really understand  the corresponding integer thing.  Do you mean
mask the data?
I think I found out my answere though.  That is non text files can only be
created/used/viewed within a program.

        -Ben

Re:non text files in pascal


On Fri, 25 Apr 1997 23:31:11 -0700, Lovina Chahal

Quote
<cha...@ix.netcom.com> wrote:
>Ben Kelley wrote:

>> I have a question.  Whenever I create a record file in pascal, I dont seem
>> to be able to read it in a text editor.  I get garbage.  Any ideas?  For
>> example....

>> GymType = record of
>>                 Name : Text;
>>                 Locker : Integer;
>>                 Age : Integer;
>>               end;
>> FileType  = File of GymType;

>> Okay, now I run this program and store values in the file.  Then when I
>> exit the program and look at the file created, I see garble dee gook.  How
>> can I create a non text file, that is read by a program??
>>         -tia  Ben
>TEXT editor..any key words....
>TEXT....to a text file you must write chars...
>you must give the corresponding integer a char so that you may
>write it.

>]] Jason Chahal [[
>       JESUS <>< rules...

Er... Ben. You're mistaking one thing for another. In Pascal, the type
TEXT that you used in your record refers to a text file. In the record
above, every member of your gym doesn't have a name, he has an entire
text file assigned to him!

Names and other things that humans (as opposed to programmers) refer
to as "text", we programmers call "strings" (and to store these in
Pascal, we se the STRING type). Your record will work much better if
it looks like this:

        GymType = record
                Name: string[50];
                Locker: integer;
                Age: integer;
                end;

In this example, the value 50 indicates that names will be no longer
than (that is, a maximum length of) 50 characters. If you think the
names of club members will be longer than that, you can change the
value to anything up to 255.

Please let me know if you need more help.

--
Maurice Valmont
West Palm Beach, FL

Re:non text files in pascal


Quote
"Ben Kelley" <mz...@tir.com> wrote:
>I have a question.  Whenever I create a record file in pascal, I dont seem
>to be able to read it in a text editor.  I get garbage.  Any ideas?  For
>example....
>GymType = record of
>            Name : Text;
>            Locker : Integer;
>            Age : Integer;
>          end;
>FileType  = File of GymType;
>Okay, now I run this program and store values in the file.  Then when I
>exit the program and look at the file created, I see garble dee gook.  How
>can I create a non text file, that is read by a program??
>    -tia  Ben

You are not supposed to be able to read it in a text editor. If  you
wich to do so you would have to use a text file as in

var destination:  text;
        your_record: gymtype;

assign(destinatio,'somefilename');
open(destination);

writeln(destination,your_record.name);
etc

I don't see any other options for being able to see the contents in a
text editor.

Poul

Re:non text files in pascal


I think I should give you all the context of the situation.  For a test in
A.P. Computer science, we had to write a program that  gathered data,
stored it in a file, read the file and analyzed the data.  So I wrote this
program and showed it too my lame computer teacher.  She ran it and it
worked.  Then she went to look at the actuall test file that was created,
and saw trash.  She told me that I didnt do the program correctly.  Of
course, this was the worst way to check to see if the program used a file.
Instead I commented out the GetData procedure and ran it.  The program
produced the same results.  Hence  I DID use a  file.  Heres a copy of the
program...
(I also tried to  expain to her why the file looked the way it did) (also
on the test, she did not say to use a text file.  The use of a nontext file
seemed more natural to me)

program Test9 (input, output, DataFile);
{Ben Kelley test 9}
const
     DATAFILENAME = 'DATA.DAT';
type
    DataType = record
                 High,
                 Low,
                 Avg : real;
               end;
    DataFiType = file of DataType;
var
   DataFile : DataFiType;
   Data : DataType;
   Choice : char;
{------------------------------------------------}
procedure GetData (var Data : DataType);
begin
     with Data do
          begin
               write ('Enter high temp : ');
               readln (High);
               write ('Enter low temp : ');
               readln (Low);
               write ('Enter average temp : ');
               readln (Avg);
               writeln;
          end
end; {GetData}
{------------------------------------------------}
procedure Analyze (var Data : DataType);
var
   loop : integer;
   HighSoFar, LowSoFar, Temp : real;
begin
     assign (DataFile, DATAFILENAME);
     reset (DataFile);
     HighSoFar := 0;
     LowSoFar := 100;
     for loop := 0 to (FileSize(DataFile) -1) do
         begin
              seek (DataFile, loop);
              read  (DataFile, Data);
              Temp := Data.High;
              if Temp > HighSoFar
                 then HighSoFar := Temp;
              Temp := Data.Low;
              if Temp > LowSoFar
                 then LowSoFar := LowSoFar;
           end;{loop}
     writeln (HighSoFar);
     writeln (LowSoFar);
end;{analyze}
{------------------------------------------------}
begin {main}
     assign (DataFile, DATAFILENAME);
     rewrite (DataFile);
     repeat
           GetData (Data);
           write (DataFile, Data);
           writeln;
           write ('process another record? (Y/N): ');
           readln (Choice);
     until not  (Choice in ['Y','y']);
     close (DataFile);
     Analyze (Data);
end.{main}

Re:non text files in pascal


Quote
"Ben Kelley" <mz...@tir.com> wrote:

//--I think I should give you all the context of the situation.  For a test in
//--A.P. Computer science, we had to write a program that  gathered data,
//--stored it in a file, read the file and analyzed the data.  So I wrote this
//--program and showed it too my lame computer teacher.  She ran it and it
//--worked.  Then she went to look at the actuall test file that was created,
//--and saw trash.  She told me that I didnt do the program correctly.  Of
//--course, this was the worst way to check to see if the program used a file.
//--Instead I commented out the GetData procedure and ran it.  The program
//--produced the same results.  Hence  I DID use a  file.  Heres a copy of the
//--program...
//--(I also tried to  expain to her why the file looked the way it did) (also
//--on the test, she did not say to use a text file.  The use of a nontext file
//--seemed more natural to me)
//--
[source snipped]

I looked at your program and again. But I don't understand your
question. I read your previous posting where you asked how it was
possible to read a binary file in a text editor. It isn't possible
because some characters aren't shown correctly(i.e. 013h(enter))

To read the file again you should use the same file-type again (but I
bet you already knew that). So I think I would express everybody's
feelings if I would say: 'Could you please rephrase your question?'

Greetings

+-------------------------------------------------------
+ EMAIL: Ned...@WorldOnline.nl
+ WWW: http://www.worldonline.nl/~nederm
+=======================================================
+ AKA Mighty Research
+
+-------------------------------------------------------
If you got a cool pascal source thingie just give
me an email....

Explorer         [not responding]      arggghhhhhhh

Other Threads