Pascal Problem 
Author Message
 Pascal Problem

Here's my problem:  I have a variable (call it s ) and I write it to a
file (call it f) and then I clear it using  s := '';  
and then I write something else to the variable and this goes to the file.
 Then I show the contents of the file (f) using assign and reset.  But
when I reset the file (f)and have each line read like this:
   ( oneline: string[80] )

    while not EOF (f) do
      begin
       readln (f, oneline);
       writeln (oneline)
      end;

After doing this, there are still two spaces read, but one is blank (from
when I cleared the variable) and the other has the information that I
wrote before.  How do I get rid of the blank line so that only the line
that I wrote something to is shown?  Thanx for your help




Wed, 18 Jun 1902 08:00:00 GMT  
 Pascal Problem

Patrick, I see nothing wrong with the way you are reading the lines, so if
you are reading a blank line from the file, it must be because you wrote
one there.

I suggest that you bench test the procedure you used to write to the file.  
If you still can't find the problem after reading and thinking about the
statements you've written, put them in a follow-up message and we'll try to
explain what you are doing wrong.

                      ...red

Knowledge is one of the few things that you
can give away and still keep for yourself.

Quote:

>Here's my problem:  I have a variable (call it s ) and I write it to a
>file (call it f) and then I clear it using  s := '';  
>and then I write something else to the variable and this goes to the file.
> Then I show the contents of the file (f) using assign and reset.  But
>when I reset the file (f)and have each line read like this:
>   ( oneline: string[80] )

>    while not EOF (f) do
>      begin
>       readln (f, oneline);
>       writeln (oneline)
>      end;

>After doing this, there are still two spaces read, but one is blank (from
>when I cleared the variable) and the other has the information that I
>wrote before.  How do I get rid of the blank line so that only the line
>that I wrote something to is shown?  Thanx for your help





Wed, 18 Jun 1902 08:00:00 GMT  
 Pascal Problem

Quote:

>Patrick, I see nothing wrong with the way you are reading the lines, so if
>you are reading a blank line from the file, it must be because you wrote
>one there.

AFAIR, not quite.  Some software interprets CR as "move to Col.1" and LF
as "Move down a row with respect to the text", whereas (AIUI) Readln(S)
treats CR as EOL and ignores a subsequent LF.

Hence if somehow you have got "Text1 CR CR LF Text2", it will often show
as "Text1/Text2" but can look to Readln like "Text1//Text2".
--
John Stockton, Surrey, UK.  Turnpike v1.12.  MIME.



Wed, 18 Jun 1902 08:00:00 GMT  
 Pascal Problem

.>
.>Here's my problem:  I have a variable (call it s ) and I write it to a
.>file (call it f) and then I clear it using  s := '';  
.>and then I write something else to the variable and this goes to the file.
.> Then I show the contents of the file (f) using assign and reset.  But
.>when I reset the file (f)and have each line read like this:
.>   ( oneline: string[80] )
.>
.>    while not EOF (f) do
.>      begin
.>       readln (f, oneline);
.>       writeln (oneline)
.>      end;
.>
.>After doing this, there are still two spaces read, but one is blank (from
.>when I cleared the variable) and the other has the information that I
.>wrote before.  How do I get rid of the blank line so that only the line
.>that I wrote something to is shown?  Thanx for your help
.>

.>

     What are the types of the variables "s" and "f"?  I'm assuming the
following:

  VAR
   s : char;
   f : text;

     Next, how is f being written?  Which represents the correct code?

     s := 'a';                  s := 'a';
     write (f, s);              writeln (f, s);
     s := ' ';                  s := ' ';
     s := 'b';                  s := 'b';
     write (f, b);              writeln (f, b);

[The key question is, are you using "write" or "writeln"?].

     I realized in the code example above that you specified s := '', which
suggests that s might be a Borland type (i.e. non-Standard Pascal) of
"string", which I know little about.  If this is so, then what I'm about to
say may be wrong (since I don't know how Borland handles this non-standard
data structure ...).

     Generally, when using read/readln with file variables of type "text",
there is a marker (implementation-dependent) that defines the end of the
line (eoln).  I believe that, according to the Pascal standard, you can
read up to, and including, this end-of-line character, which reads as a
space.  To test whether the space you read was or was not the EOL character,
you can use the eoln(f) function.

Bob Schor
Pascal Enthusiast



Wed, 18 Jun 1902 08:00:00 GMT  
 Pascal Problem

Quote:

>Here's my problem:  I have a variable (call it s ) and I write it to a
>file (call it f) and then I clear it using  s := '';  
>and then I write something else to the variable and this goes to the file.
> Then I show the contents of the file (f) using assign and reset.  But
>when I reset the file (f)and have each line read like this:

no need for another assign, just reset(f);

Quote:
>   ( oneline: string[80] )
>    while not EOF (f) do
>      begin
>       readln (f, oneline);
>       writeln (oneline)
>      end;
>After doing this, there are still two spaces read, but one is blank (from
>when I cleared the variable) and the other has the information that I
>wrote before.  How do I get rid of the blank line so that only the line
>that I wrote something to is shown?  Thanx for your help

The code that does the writing would be useful to see. I assume
something like:
...
var s:string[80];
file    f:text;

assign(f:"data.dat");
rewrite(f);
s:='something1';
writeln(f,s);
s:=' ';
s:='something2';
writeln(f,s);
...

If the second writeln(f,s) occurs before you input new text to 's'
then the blank will be written to the output file.

---------------------------------------


- - ...  ... - -



Wed, 18 Jun 1902 08:00:00 GMT  
 Pascal Problem


Quote:

>> Then I show the contents of the file (f) using assign and reset.  But
>>when I reset the file (f)and have each line read like this:

>no need for another assign, just reset(f);

In fact, calling assign() without a call to close() before will cause
a bug, because the file will never be closed.

Duncan Murdoch



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Pascal Problem...Array[0] in String.

2. Pascal-problems

3. Pascal problem password prog

4. How to train a genius. was: Pascal Problem

5. Borland Pascal problem running under DOS OS/2 session

6. PASCAL Problem

7. Foxpro RUNning Pascal - problem in sharing files - HELP!

8. Turbo Pascal Problem

9. free pascal problem

10. Simple Pascal Problem

11. Free Pascal problems

12. Pascal Problem

 

 
Powered by phpBB® Forum Software