• C

C, how to get minute value

I just want to get the current minute of from the current time.  I am using C on Linux OS.  Also be sure that there's no memory leak, since I am in an infinite loop reading the minute value.
rgbcofAsked:
Who is Participating?
 
Olivier HupéConnect With a Mentor Commented:
This should be a good start :

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char*argv[])
{
struct tm *tm;
time_t t;
int loop=0;
while (loop<1000)
{
time(&t);
if(time(&t) == (time_t) -1) printf("Something is rotten around here\n");
else {
	tm=localtime(&t);
	if (tm) printf("Current minute:second : %2d:%2d\n",tm->tm_min,tm->tm_sec);
	else printf("localtime failed\n");
}
loop++;
sleep(1);

}

exit(EXIT_SUCCESS);
}

Open in new window

0
 
ozoCommented:
see
man localtime
0
 
rgbcofAuthor Commented:
let me rephrase the questions, I just want seconds since epoch.
0
 
ozoCommented:
man 3 time
0
 
rgbcofAuthor Commented:
Very close to what I was looking for.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.