This message was supposed to be me asking for help with this program but I found the problem but came up with a question. In the above code I forgot the & sign right after scanf, no big deal just a typo but my compiler didn't catch it yet every time I ran the program it would crash and ask if I wanted to send an error report, can someone elaborate a bit on why it is so important but doesn't show up?
int userNum = 0; /*Declare all variables*/
printf("Please enter a number: \n"); /*Ask for user input and record it to: userNum*/
if( userNum = 1) /*Compare userNum to 1 and print corresponding answer*/
printf(" Your number equals 1" );
printf(" Your number does not equal 1");
P.S. Here is the fixed one:
What compiler are you using? It should have given you a warning about the following line like "Possibly incorrect assignment......".
You actually need two equal signs here ortherwise you are really assigning userNum to 1.
change it to:
if( userNum == 1)
As for the "&" in the scanf in K&R second edition page 157 they state that all arguments after the formats must be pointers. Since you defined userNum as an int and not a pointer to an int you need to supply the "&" to reference the actual address of userNum and in effect make it a pointer.
I can't believe your operating system didn't give you a "Null pointer assignment" error message without the "&".