C Programming


	/* TIME.C  Program updates time by 1 second using functions */
	#include <stdio.h>

	struct time {
	    int hour, minutes, seconds;
	};

	void time_update( struct time );	/* ANSI function prototype */

	/* function to update time by one second */
	void time_update( struct time new_time )
	{
		++new_time.seconds;
		if( new_time.seconds == 60) {
			new_time.seconds = 0;
			++new_time.minutes;
			if(new_time.minutes == 60) {
				new_time.minutes = 0;
				++new_time.hour;
				if(new_time.hour == 24)
					new_time.hour = 0;
			}
		}
	}

	main()
	{
		struct time current_time;

		printf("Enter the time (hh:mm:ss):\n");
		scanf("%d:%d:%d", \
			&current_time.hour,&current_time.minutes,&current_time.seconds);
		time_update ( current_time);
		printf("The new time is %02d:%02d:%02d\n",current_time.hour, \
			current_time.minutes, current_time.seconds);
	}

©Copyright B Brown. 1984-1999. All rights reserved.