Learn how to use File IO - easy!
Author |
Message |
MysticVegeta
|
Posted: Tue Nov 23, 2004 5:17 pm Post subject: Learn how to use File IO - easy! |
|
|
Learn how to use File IO ->
Ok, first to clear up the name, FileIo means File Input and Output. At the end of this tutoial, you willl be able to import files into turing program and save them with other name! Ok, here we go...
1) Open a blank file, type anything on it and save the file where your text file
is -> C:/somin/somin
2) Make a text file on that same directory and name it "IoOpen.txt" without the quotes, enter the number 99 on it and save the file. (For the basics, we will use only 1 line of data)
3) Open your turing file, erase everything you typed before. Now, enter this code:
code: |
% Reading part
var one, line : int
open : one, "IoOpen.txt", get
get : one, line
close (one)
|
Instead of "one", you can assign any number but it HAS to be int type because thats the stream number. Be sure that if you change it to somthing else, change the other locations where it is used too.
Same goes for the "line", but line can be any string, int, real depending on the data of the txt file.
NOTE: you HAVE to assgin the close command so that it stops executing.
Next is the writing part:
code: |
% Second and writing part
open : one, "IoOut.txt", put
put : one, line
close (one)
|
Again, you can assign any file name to export it in and remember to use the same stream numbers and line number.
We will get into arrays later, then we will be able to import and export multiple line using only a few commands!!!!!!!! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Mazer
|
Posted: Tue Nov 23, 2004 5:43 pm Post subject: (No subject) |
|
|
Before somebody flames you, I just wanted to comment that we probably already had at least one tutorial about fileIO. Having said that, nice tutorial. It's good to see people writing them once in a while (shows us that you know some useful stuff).
I'd just like to point out that it'd probably be best not to name your file variable with a number. Even though it stores an integer, in a larger program you probably won't have any idea what that integer will be. I usually name mine fileStream (or "fs" when I'm being very lazy).
Aside from that, good job. |
|
|
|
|
|
wtd
|
Posted: Tue Nov 23, 2004 9:14 pm Post subject: (No subject) |
|
|
Coutsos wrote: Before somebody flames you, I just wanted to comment that we probably already had at least one tutorial about fileIO. Having said that, nice tutorial. It's good to see people writing them once in a while (shows us that you know some useful stuff).
I'd just like to point out that it'd probably be best not to name your file variable with a number. Even though it stores an integer, in a larger program you probably won't have any idea what that integer will be. I usually name mine fileStream (or "fs" when I'm being very lazy).
I go one step further, using things like "inputFile" or "ouputFile" as appropriate. |
|
|
|
|
|
Mazer
|
Posted: Tue Nov 23, 2004 9:50 pm Post subject: (No subject) |
|
|
I knew you'd have something to say about it.
You're right, of course. |
|
|
|
|
|
|
|