Hi,
I have the problem of passing of more lines which I find really difficult, cause I am not experienced in C.
First Log file.
------------------------- Cat 1------ cat2-----------------
19.867: [Testdata 98095K->24545K(942080K), 0.1468955 secs]
19.845: [Testdata2 98095K->24545K(942080K), 0.1468955 secs]
I can pass it using
sscanf(line, "%*s %s %s %dK->%dK(%d%*s %d.%s %*s", &c, b, &r, &a, &o, &d, test)
but the second log file has the same information stored in the follwing way.
testdata
cat1 : 91.00 K
cat2 : 4.11 K
testdata2
cat1 : 911.00 K
cat2 : 24.11 K
I want to abstract cat1 and cat2 for every testdata.
But my problem is that I can only read a line at one time.
How can I save the position of file and give for every testdata: cat1 and cat2 simultaneously.
would appreciate anyy suggestions-
4 1263
Hi,
I have the problem of passing of more lines which I find really difficult, cause I am not experienced in C.
First Log file.
------------------------- Cat 1------ cat2-----------------
19.867: [Testdata 98095K->24545K(942080K), 0.1468955 secs]
19.845: [Testdata2 98095K->24545K(942080K), 0.1468955 secs]
I can pass it using
sscanf(line, "%*s %s %s %dK->%dK(%d%*s %d.%s %*s", &c, b, &r, &a, &o, &d, test)
but the second log file has the same information stored in the follwing way.
testdata
cat1 : 91.00 K
cat2 : 4.11 K
testdata2
cat1 : 911.00 K
cat2 : 24.11 K
I want to abstract cat1 and cat2 for every testdata.
But my problem is that I can only read a line at one time.
How can I save the position of file and give for every testdata: cat1 and cat2 simultaneously.
would appreciate anyy suggestions-
I'd say to build a simple state machine to keep track of what testdata your working on - so, for example:
1. read a line
2. see if it's a blank line - if it is go back to #1
3. see if it's a "testdata" line - if it is stick it into some container, then go back to #1
4. if it's not a "testdata" line parse the line to get the "catx" and "xxxK" data
5. do whatever it is you do to associate the "testdata" entry you found in #3 with the "catx" and "xxxK" data sets you found in #4 (maybe you will store them up in an array somewhere, or maybe you just output them on the fly, whatever)
hi mac,
thank you for the fast reply.
but I am a newbie to c and don't know exactly how can i make a state machine mechanism.
is it like a case command in java? If then can you explain me or give a reference where i can look for it.
hi mac,
thank you for the fast reply.
but I am a newbie to c and don't know exactly how can i make a state machine mechanism.
is it like a case command in java? If then can you explain me or give a reference where i can look for it.
A state machine is just whatever system you use to keep track of what you are doing in relation to what you have done before. The way I described it in the last post I imagined you would use something like this: -
char current_line[512];
-
-
while( /* loop until your out of input */ )
-
{
-
... read a line from the log file into current_line ...
-
-
if( /* current_line is a "textdata" */ )
-
{
-
/* starting a new set of entries, if you have a
-
* collection place put textdata_line_holder
-
* and your cat data in there now - or just
-
* output them or whatever */
-
... code to do that ...
-
-
/* you just copied off your textdata and cat data
-
* or output them or whatever - now clear out your
-
* temporary variables - (reset your state) */
-
... code to clear temps ...
-
-
/* now you've finished cleaning up you can start
-
* tracking the next entry - copy the line so you can
-
* collect or output it when you finish getting the
-
* cat entries */
-
strcpy( textdata_line_holder, current_line );
-
}
-
else if( /* current_line is a cat entry */ )
-
{
-
/* extract the cat data and put is somewhere
-
* so that you can get at it later */
-
}
-
else
-
{
-
/* this is just extra - since the log file
-
* only has textdata and cat lines this
-
* must be a blank line - I don't think you
-
* need to do anything here, but it's up to you */
-
}
-
}
-
The stuff above might not be exactly what you want but it should help. I just want to give you an idea of how to structure things, not a full-blown solution.
Thank you for the help.
A state machine is just whatever system you use to keep track of what you are doing in relation to what you have done before. The way I described it in the last post I imagined you would use something like this: -
char current_line[512];
-
-
while( /* loop until your out of input */ )
-
{
-
... read a line from the log file into current_line ...
-
-
if( /* current_line is a "textdata" */ )
-
{
-
/* starting a new set of entries, if you have a
-
* collection place put textdata_line_holder
-
* and your cat data in there now - or just
-
* output them or whatever */
-
... code to do that ...
-
-
/* you just copied off your textdata and cat data
-
* or output them or whatever - now clear out your
-
* temporary variables - (reset your state) */
-
... code to clear temps ...
-
-
/* now you've finished cleaning up you can start
-
* tracking the next entry - copy the line so you can
-
* collect or output it when you finish getting the
-
* cat entries */
-
strcpy( textdata_line_holder, current_line );
-
}
-
else if( /* current_line is a cat entry */ )
-
{
-
/* extract the cat data and put is somewhere
-
* so that you can get at it later */
-
}
-
else
-
{
-
/* this is just extra - since the log file
-
* only has textdata and cat lines this
-
* must be a blank line - I don't think you
-
* need to do anything here, but it's up to you */
-
}
-
}
-
The stuff above might not be exactly what you want but it should help. I just want to give you an idea of how to structure things, not a full-blown solution.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Al Christians |
last post by:
I've got an idea for an application, and I wonder how much of what it
takes to create it is available in open source python components.
My plan is this -- I want to do a simple spreadsheet-like...
|
by: Terry |
last post by:
Hi,
This is a newbie's question. I want to preload 4 images and only when
all 4 images has been loaded into browser's cache, I want to start a
slideshow() function. If images are not completed...
|
by: Wilhelm Kutting |
last post by:
Hi i want to use the following layout:
----------------- |
| | | Text line 1
| | | Text line 2
| image.jpg | | ...
| | |
| | |
|
by: ghadley_00 |
last post by:
Hi,
I have a MS access database into which I need to import a text file
that is oriented vertically (fields are listed from top to bottom with
the value for each field appearing to the right of...
|
by: ILCSP |
last post by:
Hi, I just started learning Visual Basic (VB.NET 03) and I need to do
this small program that will read a text file we get from another
company that has survey data, parse it and flatten it out and...
| |
by: avi |
last post by:
Hello,
I am trying to vertically center text in a background image, I found a solution on this site that sets the line-height to the height of the background image. This works just fine, except...
|
by: Looch |
last post by:
Hi All,
Not sure if parsing is the correct word but here is what I'm trying to
do:
I have a method that returns a dataset that uses a select statement
that comprises three union all'd select...
|
by: python |
last post by:
I'm parsing a text file for a proprietary product that has the following
2 directives:
#include <somefile>
#define <name<value>
Defined constants are referenced via <#name#syntax.
I'm...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |