-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_file.c
More file actions
39 lines (30 loc) · 721 Bytes
/
time_file.c
File metadata and controls
39 lines (30 loc) · 721 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
29
30
31
32
33
34
35
36
37
38
39
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "main.h"
char * get_time()
{
time_t current_time;
char* c_time_string;
current_time = time(NULL);
if (current_time == ((time_t)-1))
{
(void) fprintf(stderr, "Failure to obtain the current time.\n");
exit(EXIT_FAILURE);
}
/* Convert to local time format. */
c_time_string = ctime(¤t_time);
if (c_time_string == NULL)
{
(void) fprintf(stderr, "Failure to convert the current time.\n");
exit(EXIT_FAILURE);
}
return c_time_string;
}
void print_time()
{
//read the time and date and print in out
char * ans= get_time();
printf("%s",ans);
return ;
}