Lazarus
Free Pascal => Windows => Topic started by: Bojan 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!
-
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.
-
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
-
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...
-
how did you opened the file?
-
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....
-
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:
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