In a multi-line text file, determine the number of words in each line and enter information about this in a separate line of the new file in the form: line # contains words.The file contains only words, for example "Marry Christmas" is 1 line 2 words.
I have an example, but it's not readable from a file, and why does it always return false?
main :-
open('in.txt', read, Str),
read_file(Str,Lines),
close(Str),
write(lenght(Lines)),
word_count(Lines).
read_file(Stream,[]) :-
at_end_of_stream(Stream).
read_file(Stream,[X|L]) :-
\+ at_end_of_stream(Stream),
read(Stream,X),
read_file(Stream,L).
word_count(C):- Lines(LS),
count(LS, C), true.
count([], 0).
count([L|LS], C) :- split_string(L, " ", "", W),
length(W, N1), write(lenght(W,N1)), count(LS, N2), C is N1 + N2, true.