Computer Science Canada

I need help with a File IO project

Author:  Danyn [ Mon Dec 02, 2013 1:01 pm ]
Post subject:  I need help with a File IO project

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
<Answer Here>


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<Answer Here>

Author:  Nathan4102 [ Mon Dec 02, 2013 5:25 pm ]
Post subject:  RE:I need help with a File IO project

You're going to have to give us a little more info then that if you want us to help you. Why don't you start by filling in the template questions in your OP?

Author:  Danyn [ Mon Dec 02, 2013 5:32 pm ]
Post subject:  Re: I need help with a File IO project

What the... everything disappeared..

Guess I'll have to retype it.

<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
I'm trying to cap how much is displayed on the turing screen at once when I'm reading the file. I also want to be able to use the enter key to insert line breaks but I have no luck with doing either.


Describe what you have tried to solve this problem
I've tried changing my code and adding different variations but nothing's worked so far.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


proc WriteFile
    var fileName, fileSent, fileText : string
    fileText := ""
    var stream : int
    put "Please enter the name of the file. (Remember to add the file extension)"
    get fileName : *
    cls
    put "Please enter your text (Enter STOP to stop)"
    loop
        get fileSent : *
        exit when fileSent = "STOP"
        fileText += fileSent + " "
    end loop
    open : stream, fileName, put
    put : stream, fileText
    cls
end WriteFile

proc ReadFile
    var stream : int
    var fileName, fileText : string
    loop
        put "Please enter the name of the file. (Remember to add the file extension)"
        get fileName : *
        if File.Exists (fileName) then
            put "The file exists."
            put "Press any key to continue."
            Input.Pause
            cls
            exit
        else
            put "The file does not exist."
            put "Press any key to continue."
            Input.Pause
            cls
        end if
    end loop
    open : stream, fileName, get
    assert stream > 0
    loop
        exit when eof (stream)
        get : stream, fileText : *
        put fileText
    end loop
    close : stream
    put "Press any key to continue."
    Input.Pause
    cls
end ReadFile
%%%Variables%%%
var choice : int
%%%Main Program%%%
loop
    loop
        locate (1, 1)
        put "1 - Write a text file"
        locate (2, 1)
        put "2 - Read from a text file"
        locate (3, 1)
        put "3 - Exit the program"
        locate (10, 1)
        put "Enter a command: " ..
        get choice
        exit when choice > 0 and choice < 4
        cls
        locate (11, 1)
        put "Please enter a valid number"
    end loop
    cls
    case choice of
        label 1 :
            WriteFile
        label 2 :
            ReadFile
        label 3 :
            cls
            exit
    end case
end loop





Please specify what version of Turing you are using
4.1.1


: