A
A. Marin
Hello, I'm trying to get the time:
days:hours:minutes:seconds:nanoseconds in a program in C.
With the instruction date([+FORMAT]) i can get these data, but every
time I call the system it prints out the data. I just want to store
these, ¿how can I do it?
code:
#include<stdlib.h>
#include<sys/stat.h>
#include<time.h>
#include<stdio.h>
int main(void)
{
double d=0,h=0,m=0,s=0,ns=0;
int i=0;
d=system("date +%d");
h=system("date +%H");
m=system("date +%M");
s=system("date +%S");
ns=system("date +%N");
printf("Day: %g",d);
printf("Hour: %g",h);
printf("Minute: %g",m);
printf("Second: %g",s);
printf("Nanosecond: %g",ns);
return 0;
}
Here is the output:
Day: 0 Hour: 0 Minute: 0 Second: 0 Nanosecond: 0
¿What is wrong?
Thanks in advance, A. Marin.
days:hours:minutes:seconds:nanoseconds in a program in C.
With the instruction date([+FORMAT]) i can get these data, but every
time I call the system it prints out the data. I just want to store
these, ¿how can I do it?
code:
#include<stdlib.h>
#include<sys/stat.h>
#include<time.h>
#include<stdio.h>
int main(void)
{
double d=0,h=0,m=0,s=0,ns=0;
int i=0;
d=system("date +%d");
h=system("date +%H");
m=system("date +%M");
s=system("date +%S");
ns=system("date +%N");
printf("Day: %g",d);
printf("Hour: %g",h);
printf("Minute: %g",m);
printf("Second: %g",s);
printf("Nanosecond: %g",ns);
return 0;
}
Here is the output:
Day: 0 Hour: 0 Minute: 0 Second: 0 Nanosecond: 0
¿What is wrong?
Thanks in advance, A. Marin.