Time program

This commit is contained in:
Imbus 2025-05-12 12:05:55 +02:00
parent cc5b27a3ab
commit 57d3ae36fb

24
time.c Normal file
View 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);
}