
-----------------------------------
Nikestars
Tue Dec 17, 2013 3:06 pm

File Input (variable) and Appending Files
-----------------------------------
What is it you are trying to achieve?
I'm trying to change one part into a file from a string into a real variable. As well as appending a file at the very end(without erasing the file).

What is the problem you are having?
I'm trying to change the file from a string to a real variable. I am most likely over thinking this but I have no idea how to change it. When I import a file it has to be a string (as far as I know). Therefore that file is stored in a variable,but is there a way to change it with a function or am I missing something? I've been struggling on this for a few days now and I can't think of anything. I need it to be changed due to the fact I will be adding the numbers within that file (I know that you cannot add string and int/real together). I've tried converting it from a string to a real variable (strreal) but I've never used this function before and so it didn't work for me.

No clue on how to append files correctly.

Describe what you have tried to solve this problem
I have no clue what to do or how to attempt  it. I've tried different things but nothing is working for me. I'm fairly new to file input so this is very different than what I'm use to. 

I've attempted to append the file but it says "eof attempted on incompatible stream number 2." 
I'm stuck once again.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

var f : int
var staff, compname, employees : string
var sale : string

var employeesales : real
var numberofemployee  : int
employeesales := 0
numberofemployee := 0

var highsale,lowsale : real


open : f, "staff.txt", get


put " " : 25, "SALES REPORT"

get : f, compname : *
locate (2, 20)
put compname
put " "
put " " : 15, "SELLER", " " : 21, "SALES"

loop
    exit when eof (f)
    employeesales := employeesalse + 1
    get : f, employees : *
    get : f, sale : *
    put " " : 15, employees : 31, " ", sale
end loop


locate (12, 16)
put "Total Sold:"
locate (13, 16)
put "Average Sold:"


    var streamnumber : int
    open : streamnumber, "highestandlowest.txt", put, mod, seek

    loop
        exit when eof (streamnumber)
        seek : streamnumber, *
    end loop


    put : streamnumber, " "
    close : streamnumber



Please specify what version of Turing you are using
4.1.1

Any help is appreciated, THANKS  :D  :D  :D  :D

-----------------------------------
Dreadnought
Tue Dec 17, 2013 4:26 pm

Re: File Input (variable) and Appending Files
-----------------------------------
To convert a string to an integer you can use the seek: f, *
without a loop (* indicates to seek to the end of the file).

Also, to make your code easier to read you can wrap your code in the following way

... code ...
[/code]

-----------------------------------
Nikestars
Tue Dec 17, 2013 5:39 pm

RE:File Input (variable) and Appending Files
-----------------------------------
But how would the coding look? I understand that I need to use it but what would it look like?

-----------------------------------
Tony
Tue Dec 17, 2013 6:29 pm

RE:File Input (variable) and Appending Files
-----------------------------------
all of those functions link to the documentation describing their use.

-----------------------------------
Nikestars
Tue Dec 17, 2013 6:32 pm

RE:File Input (variable) and Appending Files
-----------------------------------
I'm confused on how what to type inside it though

Can you please give me an example on what it would like with numbers and the function of each number? (For the strreal)

-----------------------------------
Dreadnought
Tue Dec 17, 2013 10:00 pm

Re: File Input (variable) and Appending Files
-----------------------------------
The documentation gives the following example
strreal ("2.5e1")
which produces 25.0
So
put strreal ("2.5e1") + 3.7
will print 28.7 as an example.

-----------------------------------
Nikestars
Thu Dec 26, 2013 5:51 pm

RE:File Input (variable) and Appending Files
-----------------------------------
Thanks :)

-----------------------------------
np_123
Sun Dec 29, 2013 3:28 pm

Re: File Input (variable) and Appending Files
-----------------------------------
Appending to a file was mentioned and Dreadnought already explained, but I thought I'd add a working example



var file : int
var filename : string := "output.txt"

open : file, filename, put, mod, seek     /*  mod (modify) allows you to change the contents of the file  */ 

seek : file, *         /*  This searches for the end of the file ex. the last character  */ 

put : file, "This appears at the end of the file" 

close : file


