回答編集履歴

1

訂正

2018/05/02 10:35

投稿

nullpon
nullpon

スコア5737

test CHANGED
@@ -1 +1,39 @@
1
+ struct tm → time_t → struct tmと変換すれば、よろしくやってくれます。
2
+
3
+ ```c
4
+
1
- #include <time.h>
5
+ #include <time.h>
6
+
7
+
8
+
9
+ void yesterday(int *y, int *m, int *d)
10
+
11
+ {
12
+
13
+ struct tm st = {0};
14
+
15
+ time_t tt;
16
+
17
+
18
+
19
+ st.tm_year = *y - 1900;
20
+
21
+ st.tm_mon = *m - 1;
22
+
23
+ st.tm_mday = *d - 1; /* 1日前の日付を設定 */
24
+
25
+
26
+
27
+ tt = mktime(&st);
28
+
29
+ st = *localtime(&tt);
30
+
31
+ *y = st.tm_year + 1900;
32
+
33
+ *m = st.tm_mon + 1;
34
+
35
+ *d = st.tm_mday;
36
+
37
+ }
38
+
39
+ ```