views:

88

answers:

2

Hi,

I am just starting out, but this piece of code is giving me a 'segmentation fault' and I can't find out what's wrong with it:

#include<stdio.h>

int main (void) {


 int number = 0;
 int lastDigit = 0;

 printf("Enter an integer: ");
 scanf("%d", number);

 number = number*10;

 printf("Number times ten is %d.\n", number);

 return 0;

}
+2  A: 
scanf("%d", number);

would be

scanf("%d", &number);

Note the ampersand.

ArunSaha
+5  A: 

scanf("%d", number) is being given the int itself, but actually needs a pointer to the int. Try scanf("%d", &number)

Mike
Oh, my bad. got it, thanks!
capex