-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathctime.c
More file actions
28 lines (22 loc) · 692 Bytes
/
ctime.c
File metadata and controls
28 lines (22 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
/* Lo scopo del programma e' di convertire un tipo time_t in una stringa
mediante l'utilizzo della funzione ctime() */
int main(void) {
time_t t;
char *str_time;
if (time(&t) < 0) {
fprintf(stderr, "Err.(%s) getting time()\n", strerror(errno));
exit(EXIT_FAILURE);
}
/* La conversione in stringa, partendo da un valore di tipo time_t */
if ((str_time = ctime(&t)) == NULL) {
fprintf(stderr, "Err.(%s) str conversion: ctime()\n", strerror(errno));
exit(EXIT_FAILURE);
}
printf("%s", str_time);
return(EXIT_SUCCESS);
}