Hello!
The example on this page
uses pointers. I understand that's to illustrate them, but is there any particular advantage to doing so?
Seems to me that most of these operations can be done using non-pointer variables?
The example on this page
HTML:
http://www.ontko.com/~rayo/cs35/pointers.html
uses pointers. I understand that's to illustrate them, but is there any particular advantage to doing so?
Seems to me that most of these operations can be done using non-pointer variables?
Code:
void hms_to_spm( int hours , int minutes , int seconds ,
int *seconds_past_midnight ) ;
void spm_to_hms( int seconds_past_midnight ,
int *hours , int *minutes , int *seconds ) ;
main()
{
int h, m, s, spm ;
printf("Enter a time (hh:mm:ss)\n" ) ;
scanf( "%d:%d:%d" , &h, &m, &s) ;
hms_to_spm( h, m, s, &spm ) ;
spm += 15 ;
spm_to_hms( spm , &h, &m, &s ) ;
printf( "The time, fifteen seconds later, is %02d:%02d:%02d\n" , h , m , s ) ;
}
void hms_to_spm( int hours , int minutes , int seconds ,
int *seconds_past_midnight )
{
*seconds_past_midnight = hours * 3600 + minutes * 60 + seconds ;
}
void spm_to_hms( int seconds_past_midnight ,
int *hours , int *minutes , int *seconds )
{
*hours = ( seconds_past_midnight / 3600 ) % 24 ;
*minutes = ( seconds_past_midnight / 60 ) % 60 ;
*seconds = seconds_past_midnight % 60 ;