Reputation: 663
I am new to Linux. I made this program for printing uptime and ideal time of my Linux machine. But everytime i run this, it shows idealtime = 0. Can i ever get idealtime=0 ?
#include<stdio.h>
int main()
{
int a,b;
FILE *fp;
fp=fopen("/proc/uptime","r");
fscanf(fp,"%d%d",&a,&b);
printf("\n\nUptime =%d \nIdealtime =%d",a,b);
fclose(fp);
return 0;
}
Upvotes: 0
Views: 1217
Reputation: 409176
It's because the values are not integers. Try this:
float a, b;
FILE *fp = fopen("/proc/uptime", "r");
fscanf(fp, "%f %f", &a, &b);
printf("Uptime = %d\nIdealtime = %d\n", (int) a, (int) b);
Upvotes: 1