また、その差は何秒か?
というプログラムを作りたいのですが、コンパイルしたらこのようなエラーが出ました。
どう修正すればよいか分からないので、教えてください。
よろしくお願いします。
C言語はあまり理解できてないので、すみません。
エラー 34: 不正な文字 ' ' (0x8140)(関数 is_negative_dhms )
エラー 59: 宣言の構文エラー(関数 main )
エラー 60: 宣言の構文エラー(関数 main )
エラー 63: パラメータ 't' は int * 型として定義されているので int は渡せない(関数 main )
エラー 64: パラメータ 't' は int * 型として定義されているので int は渡せない(関数 main )
エラー 64: パラメータ 't' は int * 型として定義されているので int は渡せない(関数 main )
エラー 65: パラメータ 't' は int * 型として定義されているので int は渡せない(関数 main )
エラー 66: パラメータ 't' は int * 型として定義されているので int は渡せない(関数 main )
エラー 83: パラメータ 't1' は int * 型として定義されているので int は渡せない(関数 main )
エラー 83: パラメータ 't2' は int * 型として定義されているので int は渡せない(関数 main )
エラー 84: 未定義のシンボル S(関数 main )
エラー 92: パラメータ 't1' は int * 型として定義されているので int は渡せない(関数 main )
エラー 92: パラメータ 't2' は int * 型として定義されているので int は渡せない(関数 main )
#include <stdio.h>
void newline(void){printf("\n");return;}
void inputDHMS(int t[]){
printf("Input D H M S: ");
scanf("%d%d%d%d",&t[3],&t[2],&t[1],&t[0]);
return;
}
void printDHMS (int t[]){
printf("%dD %dH %dM %dS",t[3],t[2],t[1],t[0]);
return;
}
int dhms2s(int t[]){
return((t[3]*24+t[2])*60+t[1])*60+t[0];
}
void dhms2sp(int t[], int *sp){
*sp = ((t[3]*24+t[2])*60+t[1])*60+t[0];
return;
}
void s2dhms(int s, int t[]){
t[0] = s%60;
s = s/60;
t[1] = s%60;
s = s/60;
t[2] = s%24;
s = s/24;
t[3] = s;
return;
}
int is_zero_dhms(int t[]){
if(t[3]==0 && t[2]==0 && t[1]==0 && t[0]==0) {return 1;}
else {return 0;}
}
int is_negative_dhms(int t[]){
if(t[3]<0) {return 1;}
else {return 0;}
}
int is_positive_dhms(int t[]){
if(is_negative_dhms(t)){return 0;}
else if (is_zero_dhms(t)){return 0;}
else {return 1;}
}
int sub_dhms(int t1[],int t2[],int s[3]){
s[0]=t1[0]-t2[0];
if(s[0]<0){s[0]=s[0]+60; s[1]=t1[1]-t2[1]-1;}
else { s[1]=t1[1]-t2[1];}
if(s[1]<0){s[1]=s[1]+60; s[2]=t1[2]-t2[2]-1;}
else { s[2]=t1[2]-t2[2];}
if(s[2]<0){s[2]=s[2]+24; s[3]=t1[3]-t2[3]-1;}
else { s[3]=t1[3]-t2[3];}
return;
}
int main(void){
int n1;
int n2;
int T1{4};
int T2{4};
int s[4];
printf("%dsec\n", &n1);
s2dhms(n1,T1);
inputDHMS(T2);printDHMS(T2);newline();
dhms2sp(T2, &n2);
if(n2 != dhms2s(T2)){
printf("Error! Results of dhms2s and dhms2sp are different.");
newline();
}
printf("秒に統一して計算した場合:\n");
if(n1-n2>0){
printf("The 1st input is %d sec larger than the last one.", n1-n2);
newline();
} else if (n1-n2 == 0){
printf("The two inputs are equal.");
newline();
} else {
printf("The 1st input is %d sec smaller than the last one.",n2-n1);
newline();
}
newline();
printf("日時分秒で計算した場合:");newline();
sub_dhms(T1,T2,s);
if (is_positive_dhms(S)){
printf("The 1st input is larger than the last one by");
printDHMS(S);
newline();
}else if (is_zero_dhms(S)){
printf("The two inputs are equal.");
newline();
} else {
sub_dhms(T2,T1, S);
printf("The 1st input is smaller than the last one by ");
printDHMS(S);
newline();
}
return(0);
}