% Author: Ahmed Sallam
% http://sallamah.weebly.com
% Date: 9/5/2014


% Write a prolog program copy_f(F,Fcopy) to copy a text file in F to another text file in Fcopy.

copy_f(F,Fcopy):-   %try copy_f('c:\\a.txt', 'c:\\b.txt'). % a.txt is a text file in your c drive
        open(F,read, X),
        open(Fcopy,write, Y),
        
        copying(X,Y),
        
        close(X),
        close(Y).

copying(X,Y):-
              get_char(X,C),
              C \= 'end_of_file',
              put_char(Y,C),
              copying(X,Y).
copying(X,Y):- !.          % just to make copy_f succeed
