• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

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.
0
rgbcof
Asked:
rgbcof
  • 2
  • 2
1 Solution
 
ozoCommented:
see
man localtime
0
 
rgbcofAuthor Commented:
let me rephrase the questions, I just want seconds since epoch.
0
 
ozoCommented:
man 3 time
0
 
OHUPECommented:
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
 
rgbcofAuthor Commented:
Very close to what I was looking for.  Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now