Re: reading a file
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 16:00:53 +0200
robannexs@xxxxxxxxx wrote:
i've got a file of the following format
10000000 records in
10000000 records out
5120000000 bytes (5.1 GB) copied, 628.835 seconds, 8.1 MB/s
how am i suppose to get the parameter 8.1MB/s on the third line?
If it has to be a C solution, then
- read lines of the file until one of them meets
NULL != strstr(line, "MB/s");
- then either scan for the given format using
if (1 == sscanf("%*[^,], %*[^,], %lf", &MegsPerSecond)) {
/* do something with MegsPerSecond */
}
- or find the last ',' using strrchr() and scan from beyond that
position for a number with strtod()
If the "MB/s" part is not fixed, you probably just want to search
for "/s" and extract the string after the last ','.
Reading arbitrary length lines with fgets() is rather hard.
Have a look at fggets() (and ggets()) from
http://cbfalconer.home.att.net/download/
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.
- References:
- reading a file
- From: robannexs
- reading a file
- Prev by Date: Re: reading a file [OT]
- Next by Date: Re: Which compiler for a learner of C?
- Previous by thread: Re: reading a file [OT]
- Next by thread: Re: reading a file
- Index(es):
Relevant Pages
|