* * *

Author Topic: Problems with w'7 (not sure)?  (Read 1685 times)

Bojan

  • Newbie
  • Posts: 3
Problems with w'7 (not sure)?
« on: January 12, 2017, 12:27:24 am »
Hi,
It took me quite a while to figure out what was happening....
Firstly, my program (opening text file, reading it, storing lines in another file) was working.
Then, after closing FPC and opening it again, my source was opened automatically but execution from editor didn't work any more.. I was staring in screed confused, checking the simple code again and again... until I closed source, find it's location and open it again to get it work again as before

Also, I had similar problem with help files - every time after closing IDE, it seems it forgets where the help files were and I had to load them again for the new session.
What I need to do to avoid this hassle?

I have another problem:
 The following loop never ends:


 while (not EOF) do      // EOF is apparently not recognised, prog never stops.
     begin
      readln(MyFile, s);
      Writeln(Myfile_out, data);
     end;


MyFile has only 3 lines, but MyFileout could be of infinite length, if I do't stop the app.

Thank you!
« Last Edit: January 13, 2017, 04:51:05 am by Bojan »

Leledumbo

  • Hero Member
  • *****
  • Posts: 7721
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Problems with w'7 (not sure)?
« Reply #1 on: January 12, 2017, 07:43:30 am »
I have another problem:
 The following loop never ends:


 while (not EOF) do      // EOF is apparently not recognised, prog never stops.
     begin
      readln(MyFile, s);
      Writeln(Myfile_out, data);
     end;


MyFile has only 3 lines, but MyFileout could be of infinite length, if I do't stop the app.
You're checking EOF of standard input, but reading from MyFile.

Handoko

  • Hero Member
  • *****
  • Posts: 1730
  • My goal: build my own game engine using Lazarus
Re: Problems with w'7 (not sure)?
« Reply #2 on: January 12, 2017, 11:41:37 am »
I like the way Leledumbo replied, telling what has done wrong without showing up the correct code, so the OP will learn from mistakes.

But if OP needs more clues, here has example code for comparing:
http://www.freepascal.org/docs-html/rtl/system/eof.html

Bojan

  • Newbie
  • Posts: 3
Re: Problems with w'7 (not sure)?
« Reply #3 on: January 12, 2017, 09:25:20 pm »
Hi guys,
Thank you for the clues.
I will check the suggested link, the hint make sense (sort of...  I am not a programmer and my last encounter with Pascal was Borland Turbo Pascal 4 I think... I only need to do a simple data processing and TP doesn't work any more on 64-bit W'7....  so please be gentle with novice).

The first problem (with directories) however sis still pending...


turrican

  • Jr. Member
  • **
  • Posts: 51
  • Pascal is my life.
    • Homepage
Re: Problems with w'7 (not sure)?
« Reply #4 on: January 12, 2017, 09:27:05 pm »
how did you opened the file?

Bojan

  • Newbie
  • Posts: 3
Re: Problems with w'7 (not sure)?
« Reply #5 on: January 12, 2017, 11:43:12 pm »
Yep, a  bit more precise check did the trick, thank you ! :)


 while (not EOF(MyFile)) do 
     begin
      readln(MyFile, s);
      Writeln(Myfile_out, data);
     end;

I only wander, when reading MyFile reached the end of file, why I didn't stop with error, instead  MyFile_out was just filled with CR/LF, ad infinitum....

Handoko

  • Hero Member
  • *****
  • Posts: 1730
  • My goal: build my own game engine using Lazarus
Re: Problems with w'7 (not sure)?
« Reply #6 on: January 13, 2017, 02:16:21 am »
I only wander, when reading MyFile reached the end of file, why I didn't stop with error, instead  MyFile_out was just filled with CR/LF, ad infinitum....

I rarely use read and readln, but I checked the documentation and it says:
Quote
If no data is available, empty values are returned (0 for ordinal values, empty strings for string values)

In other words, it means it won't show runtime error. And perhaps you already knew, empty data will be saved as CR/LF if you're using writeln.

More info:
http://www.freepascal.org/docs-html/rtl/system/readln.html
http://www.freepascal.org/docs-html/rtl/system/read.html

please be gentle with novice

Novices are welcome here.
If you need some tutorials here you can find them with wide range of topics and usually with code included:
http://wiki.freepascal.org/Lazarus_Documentation
 ;D

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus