IO 4 - current_output(S set_output(X code_writing close(X set_output(S York University CSE 3401 V Movahedi 08_IO 18 Edinburgh Prolog Edition

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Open & Close I/O Streams Open a stream open(Filename, Mode, Stream) Filename: name of the file Mode: one of read, write, append, update Stream: the stream that has been opened Examples: open(‘myfile.txt’, read, X) open(‘output.txt’, write, X) Close a stream close(X) York University- CSE 3401- V. Movahedi 08_IO 16
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Current Streams Determine what is the current input/output current_input(Stream) current_output(Stream) Instantiate their argument to the name of the current input/output stream Changing the current input/output set_input(Stream) set_output(Stream) Set the current stream to the named stream specified by the argument The argument can be user_input / user_output York University- CSE 3401- V. Movahedi 08_IO 17
Background image of page 2
Templates program :- open(‘input.txt’, read, X), current_input(S), set_input(X), code_reading, close(X), set_input(S). program :- open(‘output.txt’, write, X),
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: current_output(S), set_output(X), code_writing, close(X), set_output(S). York University- CSE 3401- V. Movahedi 08_IO 18 Edinburgh Prolog Edition program :- see(‘input.txt’), code_reading, seen. program :- tell(‘output.txt’), code_writing, told. York University- CSE 3401- V. Movahedi 08_IO 19 • Question: Does ‘ seen’ set the input stream to the previous current stream? Try :-help(seen). to find answer. Example • Write copyfile(SrcFile, DstFile) which copies a SrcFile to DstFile one character at a time: copyfile(SrcFile, DstFile) :- open(SrcFile, read, X), open(DstFile, write, Y), current_input(SI), current_output(SO), set_input(X), set_output(Y), read_write_code, close(X), close(Y), set_input(SI), set_output(SO). read_write_code :- get_char(X), get_more(X). get_more( end_of_file ):- !. get_more(X):- put_char(X), get_char(X2), get_more(X2). York University- CSE 3401- V. Movahedi 08_IO 20...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 3401 taught by Professor Movahedi during the Fall '11 term at York University.

Page1 / 5

IO 4 - current_output(S set_output(X code_writing close(X set_output(S York University CSE 3401 V Movahedi 08_IO 18 Edinburgh Prolog Edition

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online