Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Using Text Files as a Database
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rumman




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
LaZ3R




PostPosted: 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
Aziz




PostPosted: 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.
rumman




PostPosted: 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?
Aziz




PostPosted: Mon Aug 06, 2007 10:25 am   Post subject: RE:Using Text Files as a Database

Post the code
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: