1

I know that there is a predicate :

line_count(Stream, LineCount)

but this predicate get how many numbers you are reading or writing ?, I need to append a file and before appending it, I need to check the number of the lines that have been inserted, So Is there any way I can do it with ?

Thanks,

Yasmin
  • 931
  • 3
  • 14
  • 35

1 Answers1

1

If Stream is open for writing then it's the lines that have been written. If it's open for reading it's the lines that are read.

You can open the file and read it. Then save the lines and after you open it again for writing you can count the lines you have written.

http://sicstus.sics.se/sicstus/docs/4.1.0/html/sicstus/mpg_002dref_002dline_005fcount.html

NotAUser
  • 1,436
  • 8
  • 12
  • if you tried it, you will find it always 1 because it gets to you how lines you read or write, and you are still inside the file, so each time you write, you are writting one line, and each time you read it's always one line. – Yasmin Jan 04 '13 at 15:05
  • `write_File(File,Line):- open(File, read, TempStream), read(TempStream,FileData), line_count(TempStream,Count).` – Yasmin Jan 04 '13 at 15:22
  • 1
    read/2 doesn't read the whole file. No wonder line_count gives you always 1. Try to read it as shown here http://stackoverflow.com/questions/4805601/read-a-file-line-by-line-in-prolog – NotAUser Jan 04 '13 at 15:28
  • Thanks,Yes it works if I read the whole file, but I can't do it in my case because I need to parse line by line, so I define a variable and increment it with each line I read, and send this variable to predicate where I need to check in it. – Yasmin Jan 04 '13 at 15:34