C++ Program to extract numbers from a file that is always updating with new data

Hey guys,

I need help or any ideas on how to write a C or C++ program that extracts certain numbers out of a section after the 4, 5 and 6 space.

For Example:

The output file will produce:

[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.274000 0.010000 54 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 18];...

So I want to extract the numbers 0.650000, 0.006000, 0.020000 because those are the 4,5,6 space after [ [

Another problem I have is that the output file I showed will always being updated constantly for instance as follow:

[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.2054000 0.010000 10 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 13];...

[ [1900 00 0 -1.000000 0.650000 0.006000 0.020000 2.694000 0.010000 9 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10];...

[ [1900 00 0 -2.000000 0.6023000 0.04000 0.050000 2.2454000 0.010000 5 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 12];...

And it will keep updating like this and I want to update the previous numbers I extracted with now the new numbers after the 4,5, and 6 space.

So my idea is to write a code to let it know when it encounters [ [ start looking for the 4,5,6 space and get those numbers and once it reaches ;... that's the end of that section so re-look for the next section of numbers after the 4,5,6 space.

The file will be a text file or matlab file that is always being updated with these sections of numbers. Can I make this a #include<nameoffile.h> or does .h not work with a file that is always being updated. Thank you for your input and help, it is really appreciated!
Last edited on
split input file into tokens with strtok(input," ") to extract what you need.
simple solution would be creating program like:

while(1)
{
if (file_updated) // ex. if modify time changed
{
open_file
split into tokens
save choosen tokens
close file
}
}

to see if the file has been modified you could use
http://msdn.microsoft.com/en-us/library/fa0hc0ht(v=vs.80).aspx to compare modify times
Last edited on
Thank you for your reply, the strtok function looks perfect for what I need, I will give it a try.
Topic archived. No new replies allowed.