简体   繁体   中英

Swi Prolog Read Write with Files

So I've been trying to make this encryption predicate and I got it to work for input from the keyboared and standard output but I'm failing to make it work for files,so I need help fixing it. I need to take the text in MessageFile apply the encryption and write it to OutFile.

encrypt(MessageFile,Key,OutFile):- read(X),q(X,Key,R),!,string_to_list(S,R),
write(S).

As I said it works for standard Input\\Output:

9 ?- encrypt(X,a,Y). 
|   abcdef.             
 bcdefg          
 true.

if relevant , My .pl file as well as in.txt and out.txt are in D:\\Folder

You can open a file with:

open(MessageFile, read, Read),

You can then use read/2 to read a Prolog term from the file stream:

read(Read, Term),

PS: Notice that string_to_list/2 is deprecated and string_codes/2 is its up-to-date equivalent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM