yraen
April 10th, 2008, 02:22 PM
I'll preface this with the note that I am very new to C, but have been working with VB/VBS and other scripting languages for quite some time...
What I'm trying to do is create a program to read through an actively modified text file and return statistics. As an example, I want to open a text file that is constantly added to, but I only want to read the lines from the time I select to the file to the time I tell it to stop.
Example 1:
Text file with lines in the following format: [Mon Apr 08 14:27:37] SALE $14.73
I want a loop to constantly read the newly added lines for the word "SALE", pull the dollar amount and the time stamp out, added the dollars and create a $/Second ratio output.
Example 2:
I open the file at 2:26:59 with C, then collect lines from that starting point out to give me a real time number output
It would read the line, then update 3 (or 1) labels with the corresponding Time/Dollars/ratio after doing the math to get the numbers.
[Mon Apr 08 14:27:00] SALE $14.73
Time: 0
Dollars: 14.73
$/Second: 14.73
[Mon Apr 08 14:27:54] SALE $21.12
Time: 54
Dollars: 35.85
$/Second: 0.66
[Mon Apr 08 14:28:21] SALE $4.67
Time: 81
Dollars: 40.52
$/Second: 0.50
[Mon Apr 08 14:28:39] SALE $31.54
Time: 99
Dollars: 72.06
$/Second: 0.73
[Mon Apr 08 14:29:00] SALE $19.24
Time: 120
Dollars: 91.30
$/Second: 0.76
[Mon Apr 08 14:29:12] SALE $2.03
Time: 132
Dollars: 93.33
$/Second:
[Mon Apr 08 14:29:45] SALE $15.94
Time: 165
Dollars: 109.27
$/Second: 0.71
[Mon Apr 08 14:30:27] SALE $12.87
Time: 201
Dollars: 122.14
$/Second: 0.61
[Mon Apr 08 14:30:29] SALE $6.42
Time: 209
Dollars: 128.56
$/Second: 0.62
[Mon Apr 08 14:31:47] SALE $28.89
Time: 287
Dollars: 157.45
$/Second: 0.55
[Mon Apr 08 14:31:50] SALE $17.40
Time: 290
Dollars: 174.85
$/Second: 0.60
[Mon Apr 08 14:32:04] SALE $11.33
Time: 304
Dollars: 186.18
$/Second: 0.61
[Mon Apr 08 14:32:26] SALE $1.04
Time: 326
Dollars: 187.22
$/Second: 0.57
I don't necessarily want the code to do this, just some direction. I want this to utilize the fewest PC resources as possible (it will be running alongside other applications). My main questions here are how to loop the file read without maxing the CPU usage, how to read only the new lines, and the slightly smaller question of how to do the math on the times.
Any help is appreciated, thanks!
What I'm trying to do is create a program to read through an actively modified text file and return statistics. As an example, I want to open a text file that is constantly added to, but I only want to read the lines from the time I select to the file to the time I tell it to stop.
Example 1:
Text file with lines in the following format: [Mon Apr 08 14:27:37] SALE $14.73
I want a loop to constantly read the newly added lines for the word "SALE", pull the dollar amount and the time stamp out, added the dollars and create a $/Second ratio output.
Example 2:
I open the file at 2:26:59 with C, then collect lines from that starting point out to give me a real time number output
It would read the line, then update 3 (or 1) labels with the corresponding Time/Dollars/ratio after doing the math to get the numbers.
[Mon Apr 08 14:27:00] SALE $14.73
Time: 0
Dollars: 14.73
$/Second: 14.73
[Mon Apr 08 14:27:54] SALE $21.12
Time: 54
Dollars: 35.85
$/Second: 0.66
[Mon Apr 08 14:28:21] SALE $4.67
Time: 81
Dollars: 40.52
$/Second: 0.50
[Mon Apr 08 14:28:39] SALE $31.54
Time: 99
Dollars: 72.06
$/Second: 0.73
[Mon Apr 08 14:29:00] SALE $19.24
Time: 120
Dollars: 91.30
$/Second: 0.76
[Mon Apr 08 14:29:12] SALE $2.03
Time: 132
Dollars: 93.33
$/Second:
[Mon Apr 08 14:29:45] SALE $15.94
Time: 165
Dollars: 109.27
$/Second: 0.71
[Mon Apr 08 14:30:27] SALE $12.87
Time: 201
Dollars: 122.14
$/Second: 0.61
[Mon Apr 08 14:30:29] SALE $6.42
Time: 209
Dollars: 128.56
$/Second: 0.62
[Mon Apr 08 14:31:47] SALE $28.89
Time: 287
Dollars: 157.45
$/Second: 0.55
[Mon Apr 08 14:31:50] SALE $17.40
Time: 290
Dollars: 174.85
$/Second: 0.60
[Mon Apr 08 14:32:04] SALE $11.33
Time: 304
Dollars: 186.18
$/Second: 0.61
[Mon Apr 08 14:32:26] SALE $1.04
Time: 326
Dollars: 187.22
$/Second: 0.57
I don't necessarily want the code to do this, just some direction. I want this to utilize the fewest PC resources as possible (it will be running alongside other applications). My main questions here are how to loop the file read without maxing the CPU usage, how to read only the new lines, and the slightly smaller question of how to do the math on the times.
Any help is appreciated, thanks!