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 1268
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 application:
I've used a wxGrid, so I expect that wxPython will do fine for the user
interface. The spreadsheet can be organized vertically, one...
|
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 loaded into cache,
the slideshow doesn't look very nice.
I am not sure how/when to call the slideshow() function to make sure it
starts after...
|
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 the field name (with
a "|" as a delimiter)). The text file will only have 1 record's data.
I would ideally like to setup a linked table to import...
|
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 make
single strings out of the records in it. The major difference between
this space delimited file from the many examples in these groups is...
| |
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 when the text is too long that it wraps.
div.module h2{
width:178px;
width:"182px";
height:28px;
font-family:"Avenir Black", verdana, geneva,...
|
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 statements (i.e. "select
author from table1 union all select author from table 2...").
The end result is a small dataset with one column and four...
|
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 looking for a single text stream that results from processing a file
containing these directives. Even better would be an iterator(?) type
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |