-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.c
73 lines (62 loc) · 1.56 KB
/
date.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include<time.h>
int main(int argc, char* argv[]){
time_t t1=time(NULL);
time_t t2=time(NULL);
struct tm* local;
struct tm* gmt;
local = localtime(&t1);
gmt = gmtime(&t2);
char s[100];
char s1[100];
strftime(s,sizeof(s),"%c",local);
strftime(s1,sizeof(s1),"%c",gmt);
if(argc==1){
printf("%s\n",s);
}
else if(argc==2){
if (strcmp(argv[1],"-I")==0){
printf("%d-%d-%d\n",local-> tm_year+1900,local->tm_mon+1,local->tm_mday);
}
else if(strcmp(argv[1],"-u")==0){
printf("%s\n",s1);
}
else if(strcmp(argv[1],"+%a")==0){
char *arg[10];
int i=0;
arg[i]=strtok(s," ");
while (arg[i]!=NULL)
{ i++;
/* code */
arg[i]=strtok(NULL," ");
}
printf("%s\n",arg[0]);
}
else if(strcmp(argv[1],"+%b")==0){
char *arg[10];
int i=0;
arg[i]=strtok(s," ");
while (arg[i]!=NULL)
{ i++;
/* code */
arg[i]=strtok(NULL," ");
}
printf("%s\n",arg[1]);
}
else
{
printf("Error invalid input: only -I , +%b and +%a allowed ");
}
}
else
{
/* code */
printf("Error invalid input too many operands");
}
return(0);
}