Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kdum8

macrumors 6502a
Original poster
Sep 8, 2006
919
12
Tokyo, Japan
Hi,

I am still a C beginner so I may have missed something in this code, but I keep getting bus error when I enter a value. I have searched through the code carefully and can't find where any errors could be. Any thoughts?

Code:
#include <stdio.h>

/*	This code illustrates the modulus operator. It takes the user inputted number of seconds
	and converts them into hours, minutes, and seconds. Notice the "%" command on lines 22 & 23
	which gives the remainder when the first operand is divided by the second operand. */
	

	/* Firstly define the constants to be used in the code */
	
	#define SECS_PER_MIN 60
	#define SECS_PER_HOUR 3600
	
	unsigned seconds, minutes, hours, secs_left, mins_left;

main()
{
	printf("Enter the number of seconds (< 65000): ");
	scanf("%d, &seconds");
	
	hours = seconds/SECS_PER_HOUR;
	minutes = seconds/SECS_PER_MIN;
	mins_left = minutes % SECS_PER_MIN;
	secs_left = seconds % SECS_PER_MIN;
	
	printf("%u seconds is equal to ", seconds);
	printf("%u h, %u m, and %u s\n", hours, mins_left, secs_left);
	
	return 0;
}

I can't see any error in the code unless I am missing something. I am running this on a MBP using OS 10.5.6 in the terminal. I compiled using gcc.

Any help much appreciated.

:eek:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.