-
Reading/Writing from file periodically
Hello
I have started programming only a short while ago and I am having difficulty
implementing the following problem using C++
Given a flat file containing about 1000 records, I need to read the file
3 records at a time once every 10 minutes until the end of file is reached.
Is there any time command in C++ which will let me read portions of a file
in given time intervals ?
Each time I read 3 records, I need to write these into new files (in the
same directory) and store them for later use. Currently, I am calling these
1.dat, 2.dat etc - but how can I get a generic i.dat file (which I can put
in a loop) for each iteration and store this for later use ?
Thanks,
PV
-
Re: Reading/Writing from file periodically
you have three major steps in your app: read the file (it doesn't matter
how many you need to read, the important part is to open the file, read
the records into the main memory and store the current file position so
that the next read operations starts at the correct record). The second
step consists of using a Sleep() or sleep() call. Since there is no
standard sleep function, you'll have to use whatever your compiler and
OS offer. Simply hit F1 "sleep" and learn how to use the relevant
function. Finally, write the previously read records into files whose
names are generated by tmpnam() or tmpfile(). Both are standard
functions declared in <cstdio>. Again, read the documentation on these
functions to learn how to use them.
Danny
PV wrote:
>
> Hello
>
> I have started programming only a short while ago and I am having difficulty
> implementing the following problem using C++
>
> Given a flat file containing about 1000 records, I need to read the file
> 3 records at a time once every 10 minutes until the end of file is reached.
> Is there any time command in C++ which will let me read portions of a file
> in given time intervals ?
>
> Each time I read 3 records, I need to write these into new files (in the
> same directory) and store them for later use. Currently, I am calling these
> 1.dat, 2.dat etc - but how can I get a generic i.dat file (which I can put
> in a loop) for each iteration and store this for later use ?
>
> Thanks,
> PV
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks