Time program
This commit is contained in:
parent
cc5b27a3ab
commit
57d3ae36fb
1 changed files with 24 additions and 0 deletions
24
time.c
Normal file
24
time.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main() {
|
||||
char *out = malloc(200);
|
||||
struct tm *tmp;
|
||||
|
||||
time_t t = time(NULL);
|
||||
tmp = localtime(&t);
|
||||
|
||||
if (tmp == NULL) {
|
||||
perror("localtime");
|
||||
exit(EXIT_FAILURE);
|
||||
};
|
||||
|
||||
if (strftime(out, 200, "%s", tmp) == 0) {
|
||||
fprintf(stderr, "strftime returned 0");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Result string is %s", out);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Loading…
Add table
Reference in a new issue