R
ram.ragu
here i can't typecast the value of character into double .. please
discuss the reason and solution..
/*finding the difference between job render times*/
#include <stdio.h>
#include<ctype.h>
#include<time.h>
#define LINE_LENGTH 1000
double fuction(double hour,double minute,double second);
void printline();
main()
{
char buf[LINE_LENGTH];char dummy[50],dates[11],times[9],fname[40];
int day,month,year,jobid;
int hour,minute,second;/*scan value in int then typecast into double*/
double r[100],count=0;int i=0,j[100],id=0;
FILE *ptr;
clrscr();
printf("enter the logfile name:");
gets(fname);
ptr = fopen(fname,"r");
/*freopen("myfile.txt","w",stdout);IF JOBID MORE THAN 10 USE THIS TO
GET O/P IN TEXTFILE*/
if (ptr==NULL)
{
printf("can't open file name %s",fname);
exit();
}
else
{
printline();
while (feof(ptr) == 0)
{
fgets(buf,LINE_LENGTH,ptr); /* Read next record*/
if(isdigit(buf[6]))
{
sscanf(buf,"%d %s %s %s %s %s %s",
&jobid,dummy,dummy,dummy,dummy,dates,times);
printf("%d %s %s",jobid,dates,times);
j[id]=jobid;id++;
sscanf(times,"%d:%d:%d",&hour,&minute,&second);
printf("\t
totalsec:%5.0lf\n",r[count]=function((double)hour,(double)minute,(double)second));
count++;
}
else{
continue;}
}
}
printf("----------------------------------\n");
printf("TIME DIFFERENCE BETWEEN TWO JOBS\n");
printf("----------------------------------");
for(i=0,id=0;i<count-1;i++,id++){
printf("\ndiff in time between job id %d and %d is %5.0lf
sec",j[id+1],j[id],(r[i+1]-r));}
fclose(ptr);
fclose(stdout);
}
double function(double hour,double minute,double second)
{
double s1,s2,t;
s1=(double)hour*3600;
s2=(double)minute*60;
t=(double)second+s1+s2;
return (t);
}
void printline()
{
printf("-------------------------\n");
printf("JOBID\tDATE\tTIME\tTOTAL\n");
printf("-------------------------\n");
}
discuss the reason and solution..
/*finding the difference between job render times*/
#include <stdio.h>
#include<ctype.h>
#include<time.h>
#define LINE_LENGTH 1000
double fuction(double hour,double minute,double second);
void printline();
main()
{
char buf[LINE_LENGTH];char dummy[50],dates[11],times[9],fname[40];
int day,month,year,jobid;
int hour,minute,second;/*scan value in int then typecast into double*/
double r[100],count=0;int i=0,j[100],id=0;
FILE *ptr;
clrscr();
printf("enter the logfile name:");
gets(fname);
ptr = fopen(fname,"r");
/*freopen("myfile.txt","w",stdout);IF JOBID MORE THAN 10 USE THIS TO
GET O/P IN TEXTFILE*/
if (ptr==NULL)
{
printf("can't open file name %s",fname);
exit();
}
else
{
printline();
while (feof(ptr) == 0)
{
fgets(buf,LINE_LENGTH,ptr); /* Read next record*/
if(isdigit(buf[6]))
{
sscanf(buf,"%d %s %s %s %s %s %s",
&jobid,dummy,dummy,dummy,dummy,dates,times);
printf("%d %s %s",jobid,dates,times);
j[id]=jobid;id++;
sscanf(times,"%d:%d:%d",&hour,&minute,&second);
printf("\t
totalsec:%5.0lf\n",r[count]=function((double)hour,(double)minute,(double)second));
count++;
}
else{
continue;}
}
}
printf("----------------------------------\n");
printf("TIME DIFFERENCE BETWEEN TWO JOBS\n");
printf("----------------------------------");
for(i=0,id=0;i<count-1;i++,id++){
printf("\ndiff in time between job id %d and %d is %5.0lf
sec",j[id+1],j[id],(r[i+1]-r));}
fclose(ptr);
fclose(stdout);
}
double function(double hour,double minute,double second)
{
double s1,s2,t;
s1=(double)hour*3600;
s2=(double)minute*60;
t=(double)second+s1+s2;
return (t);
}
void printline()
{
printf("-------------------------\n");
printf("JOBID\tDATE\tTIME\tTOTAL\n");
printf("-------------------------\n");
}