Data file
Author |
Message |
Tallguy
|
Posted: Mon Mar 30, 2009 1:03 pm Post subject: Data file |
|
|
if you have a data file that has
-name
-age
-grade
in it and the input looks like this . . .
Quote:
alex
17
12
kim
25
na
dave
10
5
and all of this is in one file, how do i view just one set of data, like i just want to kim's data, but not alex's or dave's, how do i search the data file for just one heading?
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Mon Mar 30, 2009 1:35 pm Post subject: RE:Data file |
|
|
You have a couple options:
Option A: You can read all of the records from the data file into some sort of structure in memory. From there, the user enters the name, and you search the structure in memory. Simple and easy.
Option B: You can read all of the file into a string, or set of strings, then look for the user name amongst them, turn it into a record on request, then print that to the screen when the user requests it. Messy and prone to failure.
I suggest looking up records and arrays and then choosing A.
|
|
|
|
|
|
saltpro15
|
|
|
|
|
zero-impact
|
Posted: Mon Mar 30, 2009 2:36 pm Post subject: RE:Data file |
|
|
I would say the easiest way of doig this would ot be just read in each line into a temporary string variable and check if it is the one you are looking for. If it isn't continue to the next line, otherwise keep that name and read in the next two lines of data that go with it.
|
|
|
|
|
|
Insectoid
|
Posted: Mon Mar 30, 2009 5:15 pm Post subject: RE:Data file |
|
|
That would be the easiest way, but not the best way. It would be extremely slow (relative to the array) as you are reading from the file far more than otherwise.
|
|
|
|
|
|
Tallguy
|
Posted: Wed Apr 01, 2009 9:12 am Post subject: Re: Data file |
|
|
okay, i got it to work thanks for your help, no i attached my program, how can i have it so that each new entry will just be added onto the exisant data, and not earse it?
Description: |
|
Download |
Filename: |
general.t |
Filesize: |
3.39 KB |
Downloaded: |
40 Time(s) |
|
|
|
|
|
|
DemonWasp
|
Posted: Wed Apr 01, 2009 12:42 pm Post subject: RE:Data file |
|
|
Either open the file for appending (sadly, I don't think this is possible in Turing), or make a simple workaround:
1. Open the file for "get"
2. Read in all the records as I suggest above.
3. Close the file.
4. Open the file for "put"
5. Output all the records you've loaded.
6. Close the file.
|
|
|
|
|
|
|
|