c - Converting proc/uptime to DD:HH:MM:SS -
i've read value of /proc/uptime (which time in seconds since last boot), , i'm trying convert into: dd:hh:mm:ss. , keep getting error: "lvalue required left operand of assignment make: *
this code:
/** * method retrieves time since system last booted [dd:hh:mm:ss] */ int kerstat_get_boot_info(sys_uptime_info *s) { /* initialize values zero's */ memset(s, 0, sizeof(sys_uptime_info)); /* open file & test failure */ file *fp = fopen("/proc/uptime", "r"); if(!fp) { return -1; } /* intilaize variables */ char buf[256]; size_t bytes_read; /* read entire file buffer */ bytes_read = fread(buf, 1, sizeof(buf), fp); /* close file */ fclose(fp); /* test if read failed or if buffer isn't big enough */ if(bytes_read == 0 || bytes_read == sizeof(buf)) return -1; /* null terminate text */ buf[bytes_read] = '\0'; sscanf(buf, "%d", &s->boot_time); &s->t_days = s->boot_time/60/60/24; &s->t_hours = s->boot_time/60/60%24; &s->t_minutes = s->boot_time/60%60; &s->t_seconds = s->boot_time%60; }
my structure looks this:
typedef struct { /* amount of time since last boot [dd:hh:mm:ss] */ /* time when system last booted */ int boot_time; int t_days; int t_hours; int t_minutes; int t_seconds; } sys_uptime_info;
i don't using int, doesn't make sense in case...i've tried double , float when do, have trouble reading value buf boot_time. appreciated!
this issue
&s->t_days = s->boot_time/60/60/24; &s->t_hours = s->boot_time/60/60%24; &s->t_minutes = s->boot_time/60%60; &s->t_seconds = s->boot_time%60;
change to
s->t_days = s->boot_time/60/60/24; s->t_hours = s->boot_time/60/60%24; s->t_minutes = s->boot_time/60%60; s->t_seconds = s->boot_time%60;
when see [error: "lvalue required left operand of assignment], first thing should check left hand side of each assignment. lvalue should resolve memory address. variable names lvalues , can likened objects. s->t_days lvalue can assigned value unlike &s->t_days. lvalues called such, because can appear on left hand side of assignment. rvalues values can appear on right hand side. in case have rvalue on left hand side of assignment operator.
Comments
Post a Comment