Computer Science Canada

how do you use eof without a file?

Author:  BigBear [ Mon May 04, 2009 6:04 am ]
Post subject:  how do you use eof without a file?

Turing:
var line : string
        loop
            exit when eof   % Are there more characters?
            get line : *    % Read entire line
            put line
        end loop


I can't seem to exit the loop, is t used correcrly?

Author:  copthesaint [ Mon May 04, 2009 7:41 am ]
Post subject:  Re: how do you use eof without a file?

Turing:
var fileNumber : int
var line : string
open : fileNumber, (FileName + ".txt"), get % opens the saved file.
    loop
        exit when eof (fileNumber) % exits when there are no more values to get.
        get : fileNumber, line : * % gets a line 1 line at a time. so its get then : to declair from where to get, then the variable to set the line from where to get the :* tells to get the whole line.
end loop
    close : fileNumber % Closes the file.
This will open a file, and no you can't just use eof because the End of File fuction requires a var of int value in it's paramiters

Author:  OneOffDriveByPoster [ Mon May 04, 2009 7:59 am ]
Post subject:  Re: how do you use eof without a file?

copthesaint @ Mon May 04, 2009 7:41 am wrote:
This will open a file, and no you can't just use eof because the End of File fuction requires a var of int value in it's paramiters
From the reference manual:
Quote:
The eof (end of file) function is used to determine if there is any more input. It returns true when there are no more characters to be read. The parameter and its parentheses are omitted when referring to the standard input (usually this is the keyboard)

Author:  BigBear [ Mon May 04, 2009 12:20 pm ]
Post subject:  RE:how do you use eof without a file?

This is from the get command

but it doesn't exit the loop also I know how to use exit when eof(fn) but what would you use for keyboard?

or is it default like it is for put you don't need to say put : scrren, or something

Author:  richcash [ Mon May 04, 2009 1:10 pm ]
Post subject:  Re: how do you use eof without a file?

From the Turing Reference, under eof:
Turing Reference wrote:
When the input is from the keyboard, the user can signal end-of-file by typing control-Z on a PC (or control-D on UNIX). If a program tests for eof on the keyboard, and the user has not typed control-Z (or control-D) and the user has typed no characters beyond those that have been read, the program must wait until the next character is typed. Once this character is typed, the program knows whether it is at the end of the input, and returns the corresponding true or false value for eof.
Your program exits for me (on Windows) when I end one of the strings with a Ctrl-Z. Either Ctrl-Z or Ctrl-D should work on whichever operating system you're using.

Author:  BigBear [ Mon May 04, 2009 4:40 pm ]
Post subject:  RE:how do you use eof without a file?

crtl - Z = it freezing

Author:  copthesaint [ Tue May 05, 2009 7:46 am ]
Post subject:  RE:how do you use eof without a file?

Im just wondering, What are you accually tring to accomplish? The Eof was made for files. What are you accually tring to do.

Author:  BigBear [ Thu May 28, 2009 2:09 pm ]
Post subject:  RE:how do you use eof without a file?

I'm not trying to do anything I am wondering why in the Turing help file it has that program when it doesn't work for me


: