delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2006/07/31/22:28:10

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Tue, 01 Aug 2006 05:26:07 +0300
From: alex bodnaru <alexbodn AT 012 DOT net DOT il>
Subject: Re: files manipulation
In-reply-to: <1154351273.909797.300920@b28g2000cwb.googlegroups.com>
To: djgpp AT delorie DOT com
Message-id: <44CEBBBF.2040501@alex3>
MIME-version: 1.0
X-Accept-Language: en-us, he
References: <1154326764 DOT 352771 DOT 157900 AT m79g2000cwm DOT googlegroups DOT com>
<44CDB467 DOT 40409 AT alex3> <1154351273 DOT 909797 DOT 300920 AT b28g2000cwb DOT googlegroups DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060607
Debian/1.7.12-1.2
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

This is a multi-part message in MIME format.

--Boundary_(ID_MqWRZyeHXHPuomRj4BXpKg)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT


hi,

you are doing right, just not showing all records.
attached your own code, slightly retouched.

alex

ram DOT ragu AT gmail DOT com wrote:
> hi
>   i can read the records. here the code is..
> /*finding the difference btween times*/
> #include <stdio.h>
> #include<ctype.h>
> #include<time.h>
> main()
> {
> char buf[1000];
> char dummy[50],dates[11],times[9];
> int day,month,year,hour,minute,second,jobid;
> FILE *ptr;
> clrscr();;
> ptr = fopen("read.txt","r");
> while (feof(ptr) == 0)
>     {
> 	fgets(buf, 1000, ptr);	/* Read next record			*/
> 	if(isdigit(buf[0]))
> 	{
> 	sscanf(buf,"%d %s %s %s %s %s
> %s",&jobid,dummy,dummy,dummy,dummy,dates,times);
> 	printf("\n\n\n\n\n\n\n\n %d %s %s",jobid,dates,times);
> 	sscanf(dates,"%d/%d/%d",&month,&day,&year);
> 	printf("\n\n\n%d %d %d",month,day,year);
> 	sscanf(times,"%d:%d:%d",&hour,&minute,&second);
> 	printf("\n\n\n %d:%d:%d",hour,minute,second);
>      	}
> 	/* printf("%s",buf);	 O/P the record to the screen		*/
>      }
>  }
> 
> 
> 
> 
>   in this code how can i go to the next records? here i can get only
> one record.. then here i want to do time difference between two
> records..
> alex bodnaru wrote:
> 
>>hi ram,
>>
>>i would open the logfile in text read mode, and fgets each line in a
>>buffer long enough.
>>of the lines read, select the ones that contain your data, as i
>>understand, those that begin with a number:
>>if (isdigit(buf[0])) { ... }
>>then scan the line data with sscanf:
>>int jobid;
>>char dummy[50], dates[11], times[9];
>>sscanf(buf, "%d %s %s %s %s %s %s", &jobid, dummy, dummy, dummy, dummy,
>>dates, times);
>>please note, thay you may need to set the proper spacing between the
>>fields in the format string.
>>now, sscanf again, to get the time integer values:
>>int day, month, year, hour, minute, second;
>>sscanf(dates, "%d/%d/%d", &month, &day, &year);
>>sscanf(times, "%d:%d:%d", &hour, &minute, &second);
>>now get the system time and do your calculations.
>>
>>good luck,
>>
>>alex
>>
>>
>>ram DOT ragu AT gmail DOT com wrote:
>>
>>>hi
>>>  i have problem which is simple but im struggling to solve it..below i
>>>gave one sample of log file which is in text file format.the problem is
>>>i have to get time in this logfile and deduct the time from system file
>>>finally i have to bring the answer to standard output.. i got idea of
>>>reading line from logfile and copy to stdout. but the problem is i
>>>can't do manipulation(getting time difference) in textfile..some body
>>>please help me out..
>>>
>>>
>>>logfile:
>>>---------
>>>
>>>jobid                                              time
>>>------------------------------------------------------------
>>>
>>>181     0 ._11CH_CAS render       qw    07/23/2005 00:08:44
>>>       112,113
>>>       Full jobname:
>>>._11CH_CAS1_q123s001_001_222_T2_ExtVeh02_SHD.ma
>>>
>>>
>>>182     0 ._11CH_CAS render       qw    07/23/2005 00:17:43
>>>       125-131:1
>>>       Full jobname:
>>>._11CH_CAS1_q123s001_001_222_T1_ExtVeh02_SHD.ma
>>>183     0 ._11CH_CAS render       qw    07/23/2005 00:27:05
>>>       125
>>>        Full jobname:
>>>._11CH_CAS1_q123s001_001_222_T2_ExtVeh02_SHD.ma
>>>184     0 ._11CH_CAS render       qw    07/23/2005 01:33:07
>>>       70-133:1
>>>      Fulljobname:
>>>._11CH_CAS1_q01s001_001_222_T3_EXTRA_VEHICALS_SHD.ma
>>>
>>>
>>>185     0 ._11CH_CAS render       qw    07/23/2005 01:36:57
>>>       70-133:1
>>>       Full jobname:
>>>._11CH_CAS1_q123s001_133_185_T3_ExtVeh03_SHD.ma
>>>
>>>
>>>the output in stdout should be like this:
>>>
>>>
>>>jobid         timedifference(this is diff between logfiletime and
>>>systemtime)
>>>-----------------------------------
>>>181             1000 minutes
>>>
>>>
> 
> 
> 

--Boundary_(ID_MqWRZyeHXHPuomRj4BXpKg)
Content-type: text/x-csrc; name=testdate.c
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=testdate.c

/*finding the difference btween times*/
#include <stdio.h>
#include<ctype.h>
#include<time.h>
main()
{
char buf[1000];
char dummy[50],dates[11],times[9];
int day,month,year,hour,minute,second,jobid;
FILE *ptr;
/*clrscr();;*/
ptr = fopen("logfile.txt","r");
while (feof(ptr) == 0)
    {
	fgets(buf, 1000, ptr);	/* Read next record*/
	if(isdigit(buf[0]))
	{
	sscanf(buf,"%d %s %s %s %s %s %s",
           &jobid,dummy,dummy,dummy,dummy,dates,times);
	printf("%d %s %s\n",jobid,dates,times);
	sscanf(dates,"%d/%d/%d",&month,&day,&year);
	printf("\t%d %d %d\n",month,day,year);
	sscanf(times,"%d:%d:%d",&hour,&minute,&second);
	printf("\t%d:%d:%d\n",hour,minute,second);
     	}
	/* printf("%s",buf); O/P the record to the screen*/
     }
     fclose(ptr);
 }


--Boundary_(ID_MqWRZyeHXHPuomRj4BXpKg)--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019