Using Text Files as a Database
Author |
Message |
rumman
|
Posted: Tue Jul 31, 2007 10:25 pm Post subject: Using Text Files as a Database |
|
|
Hi,
I am deciding on making a program. I have actually got the program to read from a text file and check whether the minute and the hour are the same. But, I want to add the functionality of having Turing to select the appropriate line according to the "day".
For example, if today is Wednesday, then in the text file, there is a line called "25 10:00". I want Turing to go to the line with "25" and then read "10:00"
Could anyone briefly describe how can I do this? I know about seek and tell, but I don't know how to use them properly. And yes, I already read the I/O File Tutorial.
Please help, Thanks. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
LaZ3R
|
Posted: Fri Aug 03, 2007 11:22 am Post subject: RE:Using Text Files as a Database |
|
|
I'm slightly confused as to what you're trying to mainly accomplish. Whether the minute and the hour are the same as what?
Turing scans through the file in order so you would most likely need an conditional exit in the loop when checking through the datafile for whatever you're exactly trying to do. I'm just slightly confused as to what it is you're trying to do so if you can clear that up a bit more, would be able to help ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Aziz
![](http://compsci.ca/v3/uploads/user_avatars/17740604804829f8242e90c.png)
|
Posted: Fri Aug 03, 2007 1:14 pm Post subject: RE:Using Text Files as a Database |
|
|
So, the line # (In your example, 25), would represent the day? So the correct time for day 25 is 10:00? Assuming that the day numbers don't go in order starting at 1 and increment by 1 each time, you simply should read in the file to an array of strings, and check if the first token (word/number without whitespace) matches the day you are looking for. Something like this:
code: | var lines : array 1 .. 100 of string
% read lines
for i : 1 .. 100
if [condition] then %[condition would check if the first part is the right day
% do something
end if
end for
|
There probably is a better way, but you'll have to wait until someone who has used Turing lately (more recently than a year and a half) comes along. |
|
|
|
|
![](images/spacer.gif) |
rumman
|
Posted: Sun Aug 05, 2007 3:07 pm Post subject: Re: Using Text Files as a Database |
|
|
Guys, i was actually able to make this program since I spent a lot of time on it now. But, the only problem is that it uses 100% of the CPU and I don't think it will be helpful since I don't want my computer to be constantly stuck.
The problem is the loop. If I take away the loops, the program won't take as much system power, but the loop is the only thing that helps me go through the file and check whether the time in the file matches with the current time.
Could anyone suggest a better way of fixing the loop so that it doesn't clog up my CPU? |
|
|
|
|
![](images/spacer.gif) |
Aziz
![](http://compsci.ca/v3/uploads/user_avatars/17740604804829f8242e90c.png)
|
Posted: Mon Aug 06, 2007 10:25 am Post subject: RE:Using Text Files as a Database |
|
|
Post the code |
|
|
|
|
![](images/spacer.gif) |
|
|