Reading from a .txt file (advanced)
Author |
Message |
chipanpriest
|
Posted: Wed Dec 21, 2011 8:31 pm Post subject: Reading from a .txt file (advanced) |
|
|
Hey I need to make a program that reads information from a .txt file and outputs it on the screen and I have the basic understanding of reading/writing from .txt file. What I need ehlp with, is if I can get turing to read only part of the line because I have the name of the event and the date on the same line but I want them saved in separate variables. I have a picture here of the text file and also heres some code:
Turing: | var cnumb, file : int
var name : string
var event : array 1 .. 3 of string
var cost : array 1 .. 3 of real
var tickets : array 1 .. 3 of int
open : file, "Events.txt", get
get : file, name : *
get : file, cnumb
get : file, event (1) : *
get : file, cost (1)
get : file, tickets (1)
put name
put cnumb
put event (1)
put cost (1)
put tickets (1)
close : file
|
Description: |
|
Filesize: |
19.18 KB |
Viewed: |
382 Time(s) |
|
Description: |
|
Filesize: |
19.18 KB |
Viewed: |
238 Time(s) |
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Dec 21, 2011 9:35 pm Post subject: RE:Reading from a .txt file (advanced) |
|
|
: * reads in the whole line. You can read in one word at a time, if you don't use it. Alternatively you could read in the entire line, and then figure out what is what in it. Perhaps with the help of index
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Aange10
|
Posted: Wed Dec 21, 2011 9:37 pm Post subject: Re: Reading from a .txt file (advanced) |
|
|
Before I begin to explain, do remember that there is more than one way to do things.
I created a Database a little while back for a game (Maplestory) to hold all my data for items. In there I needed to hold a lot of variables in the same line. So when I decided how I was going to format my text file, I decided on a system like this:
code: |
[Name] (Special) -Type- {Price} =Date=
|
After I decided on the format, I went through the file and took out all the data. (In the Turing Walkthrough, the tutorial File I/O explains how to do this. Aswell, the tutorial String Manipulation explains how to do what I'm about to talk about) Once I had all the data, I searched through each string.
Now lets say I wanted to get the name. I'd go through the string and find the first [. Then I'd go through and find first ]. Finally, I'd assign the name to whatever was between [ and ]. Then I was able to do that for everything else. Likewise, I was able to easily get information in pieces. (I'll attach the Database if you'd like to see it. Warning: It's an old project, and the code is on the bad side. Though running the program will show you it in function, the code is rather messy and inefficient.)
Description: |
|
Download |
Filename: |
MaplePrices.rar |
Filesize: |
1.61 MB |
Downloaded: |
732 Time(s) |
|
|
|
|
|
|
chipanpriest
|
Posted: Wed Dec 21, 2011 10:27 pm Post subject: RE:Reading from a .txt file (advanced) |
|
|
haha thats funny cause i actually still play maplestory xD
|
|
|
|
|
|
chipanpriest
|
Posted: Wed Dec 21, 2011 10:33 pm Post subject: RE:Reading from a .txt file (advanced) |
|
|
and thats actually sick. so you enter in items that you want to keep prices for so its kind of like a storage place for everything you enter in?
|
|
|
|
|
|
Aange10
|
Posted: Thu Dec 22, 2011 1:54 am Post subject: RE:Reading from a .txt file (advanced) |
|
|
Pretty much. I still play, too, just not much. I was going to add a remove button, and an edit button, but I have yet to. (You might notice the pictures in the file)
I may go back to developing the program, but I'd be rewriting it. It's high innefficient, and quite stupid, in all honesty.
Anyways, was your question answered?
|
|
|
|
|
|
|
|