質問編集履歴
1
tm構造体を使おうとしたけどトラブった
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,4 +62,50 @@
|
|
62
62
|
|
63
63
|
###参考ページ
|
64
64
|
[1.知恵袋](https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1128476216)
|
65
|
-
[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)
|
65
|
+
[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)
|
66
|
+
|
67
|
+
###追記
|
68
|
+
**mjd2data**にtm構造体を使ってみようとしましたが、表示されないです。使い方を間違っているのでしょうが、自前で検索しようにもワードが思いつきません。
|
69
|
+
```C
|
70
|
+
#include <stdio.h>
|
71
|
+
#include <string.h>
|
72
|
+
#include <ctype.h>
|
73
|
+
#include <stdlib.h>
|
74
|
+
#include <time.h>
|
75
|
+
#include <math.h>
|
76
|
+
|
77
|
+
void mjd2data(int mjd, struct tm *data){
|
78
|
+
int n, a, b;
|
79
|
+
//printf("n=%d",n);
|
80
|
+
a=4*n +3 +4*floor( 3/4.0* floor( 4*(n+1)/146067.0 ) );
|
81
|
+
b=5*floor(a%1461/4.0 )+2;
|
82
|
+
data->tm_year=floor(a/1461.0);
|
83
|
+
data->tm_mon =floor(b/153.0)+3;
|
84
|
+
data->tm_mday=floor(b%153/5.0)+1;
|
85
|
+
if(12 < data->tm_mon ){
|
86
|
+
data->tm_year+=1;
|
87
|
+
data->tm_mon-=12;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
char printd(struct tm *data, int fg){//fg=0なら4桁、1なら2桁
|
91
|
+
if(fg){
|
92
|
+
data->tm_year-=2000;
|
93
|
+
}
|
94
|
+
sprintf(a,"%d/%d/%d",data->tm_year,data->tm_mon,data->tm_mday);
|
95
|
+
return a;
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
void main(){
|
100
|
+
int mjd;
|
101
|
+
struct tm *data;
|
102
|
+
char *a;
|
103
|
+
scanf("%d",&mjd);
|
104
|
+
mjd2data(mjd,data);
|
105
|
+
puts("hoge");
|
106
|
+
printf("%4d/", data->tm_year);
|
107
|
+
printf("%2d/", data->tm_mon);
|
108
|
+
printf("%2d ", data->tm_mday);
|
109
|
+
printf("%s\n",printd(data,0));
|
110
|
+
}
|
111
|
+
```
|