質問編集履歴
1
tm構造体を使おうとしたけどトラブった
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,95 @@
|
|
127
127
|
[1.知恵袋](https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1128476216)
|
128
128
|
|
129
129
|
[2.Wikipedia](https://ja.wikipedia.org/wiki/%E3%83%A6%E3%83%AA%E3%82%A6%E3%82%B9%E9%80%9A%E6%97%A5)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
###追記
|
134
|
+
|
135
|
+
**mjd2data**にtm構造体を使ってみようとしましたが、表示されないです。使い方を間違っているのでしょうが、自前で検索しようにもワードが思いつきません。
|
136
|
+
|
137
|
+
```C
|
138
|
+
|
139
|
+
#include <stdio.h>
|
140
|
+
|
141
|
+
#include <string.h>
|
142
|
+
|
143
|
+
#include <ctype.h>
|
144
|
+
|
145
|
+
#include <stdlib.h>
|
146
|
+
|
147
|
+
#include <time.h>
|
148
|
+
|
149
|
+
#include <math.h>
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
void mjd2data(int mjd, struct tm *data){
|
154
|
+
|
155
|
+
int n, a, b;
|
156
|
+
|
157
|
+
//printf("n=%d",n);
|
158
|
+
|
159
|
+
a=4*n +3 +4*floor( 3/4.0* floor( 4*(n+1)/146067.0 ) );
|
160
|
+
|
161
|
+
b=5*floor(a%1461/4.0 )+2;
|
162
|
+
|
163
|
+
data->tm_year=floor(a/1461.0);
|
164
|
+
|
165
|
+
data->tm_mon =floor(b/153.0)+3;
|
166
|
+
|
167
|
+
data->tm_mday=floor(b%153/5.0)+1;
|
168
|
+
|
169
|
+
if(12 < data->tm_mon ){
|
170
|
+
|
171
|
+
data->tm_year+=1;
|
172
|
+
|
173
|
+
data->tm_mon-=12;
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
char printd(struct tm *data, int fg){//fg=0なら4桁、1なら2桁
|
180
|
+
|
181
|
+
if(fg){
|
182
|
+
|
183
|
+
data->tm_year-=2000;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
sprintf(a,"%d/%d/%d",data->tm_year,data->tm_mon,data->tm_mday);
|
188
|
+
|
189
|
+
return a;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
void main(){
|
198
|
+
|
199
|
+
int mjd;
|
200
|
+
|
201
|
+
struct tm *data;
|
202
|
+
|
203
|
+
char *a;
|
204
|
+
|
205
|
+
scanf("%d",&mjd);
|
206
|
+
|
207
|
+
mjd2data(mjd,data);
|
208
|
+
|
209
|
+
puts("hoge");
|
210
|
+
|
211
|
+
printf("%4d/", data->tm_year);
|
212
|
+
|
213
|
+
printf("%2d/", data->tm_mon);
|
214
|
+
|
215
|
+
printf("%2d ", data->tm_mday);
|
216
|
+
|
217
|
+
printf("%s\n",printd(data,0));
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
```
|