I made this program to print up time in hours,minutes and seconds
#include<stdio.h>
int main()
{
float a, b,x,mina,minb,hrsa,hrsb;
float seca,secb;
FILE *fp = fopen("/proc/uptime", "r");
fscanf(fp, "%f %f", &a, &b);
seca=(a)%60;
mina=seca/60;
hrsa=mina/60;
secb=(b)%60;
minb=secb/60;
hrsb=minb/60;
printf("Uptime=%f hrs %f min %f sec",hrsa,mina,seca);
printf("Idealtime =%f hrs %f min %f sec",hrsb,minb,secb);
return 0;
}
here i am getting an error “invalid operands to binary” in lines 12 and 16.
You can’t do mod (
%) on floats. Try((long)a)%60;Or even(long long), but the 68 years that 1<<31 seconds provides should be sufficient….Also, you need another mod operation on minutes, or else 3601 seconds becomes “1 hour 60 minutes, 1 second”, instead of “1 hour 0 minutes, 1 second”.