From nzhou@acm.org Mon Dec 1 21:21:05 2003 From: nzhou@acm.org (Neng-Fa Zhou) Date: Mon, 1 Dec 2003 16:21:05 -0500 Subject: [bp-users]Re: read from a text file Message-ID: <002c01c3b851$09124580$def9f592@ZHOULAB> You should use get_code(X) to test whether you have encountered end-of-line (X is bound to 10 if end-of-line). The program behaves the same regardless of whether you use the debugger or not. The second run gives 'yes' because 'at_end_of_strea'm succeeds, not because it is in debug mode. In B-Prolog, there is a built-in called readLine(X) (may not be documented) that reads in a line as codes. Neng-Fa Zhou bbabinu@hknetmail.com wrote: eol('\n'). % Reads a single line from a given file. % read_myline(X):-write(X),nl,fail. read_myline([]):- at_end_of_stream. read_myline([]):- peek_char(Char1), eol(Char1), get_char( _ ). read_myline([Code |Others]):- get_char(NextChar), char_code(NextChar, Code), read_myline(Others). test1(FileName):- open(FileName, read, FpStream), set_input(FpStream), read_myline(DimStr), write(DimStr), close(FpStream). this program fails to read a line from a text file....