-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetdate.c
More file actions
44 lines (36 loc) · 786 Bytes
/
Copy pathgetdate.c
File metadata and controls
44 lines (36 loc) · 786 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
40
41
42
43
44
#include <stdio.h>
#include <time.h>
#include <string.h>
int main(int argc, char** argv )
{
char* str1;
FILE * fp;
char helper1[100];
str1 = argv[1];
if (strcmp(str1, "--help")==0){ // --help flag
fp = fopen ("date.txt", "r");
if(fp == NULL) {
perror("Error opening file");
return(-1);
}
while(fgets (helper1, 600, fp)!=NULL) {
puts(helper1);
}
fclose(fp);
}
else if (strcmp(str1, "-u")==0){ //-u flag
time_t t = time(&t);
struct tm *gt = gmtime(&t);
printf("UTC %s", asctime(gt));
}
else if ( (strcmp(str1, "\n")!=0) && (strcmp(str1, "-u")!=0) && (strcmp(str1, "--help")!=0)){
printf("invalid command\n");
}
else{
time_t t = time(&t);
struct tm lt = {0};
localtime_r(&t, <);
printf("%s %s", lt.tm_zone ,ctime(&t));
}
return 0;
}