why doesn't this work
Code:
typedef struct{
char sec;
char min;
char hr;
int day;
} time;
time addtime(time t1,time t2)
{
time op;
op.min=0;
op.hr=0;
op.sec = t1.sec + t2.sec;
if(op.sec>59){
op.sec %= 60;
op.min++;
}
op.min += t1.min + t2.min;
if(op.min>59){
op.min %= 60;
op.hr++;
}
op.hr += t1.hr + t2.hr;
return op;
}
main()
{
time op,tim1,tim2;
tim1.sec=40; tim1.min=15; tim1.hr=11;
scanf("%d%d%d",&tim2.hr,&tim2.min,&tim2.sec); // THIS LINE
printf("\nTime2= %d:%d:%d",tim2.hr,tim2.min,tim2.sec);
op=addtime(tim1,tim2);
printf("\n%d:%d:%d",op.hr,op.min,op.sec);
}
In the line indicated above (scanf()) there seems to be something wrong it does not get the 2nd 2 values and gives 0,0,<correct 3rd val> on printing. I thought maybe there was something wrong in getting the values using
Code:
&tim2.hr, &tim2.min, &tim2.sec
in the scanf line, so i tried different forms such as &(tim2).hr etc... but nothing changes.
So what is the actual way to read in structure member values. (Direct assignment works but then do i have to get the values in a separate variable and then store them in the structure variable members?)