Advertisement

Unknown programming error

Started by March 03, 2001 04:09 AM
1 comment, last by rsflux 23 years, 11 months ago
I''m running into the following error message when I run my code (it compiles fine): (Program Name) has caused an error in MSVCRT.DLL (Program Name) will now close. Is anyone able to help me with this? The code bugs out when I put 3 integers into an array (''Nums''). I am running win ME and bloodshed dev-c++ with mingw compiler. The following code compiles fine and runs until the 3 integers are entered: #include int main(){ long Count, Nums[50]; int i; printf("How many numbers would you like to average? "); scanf("%i", &Count); printf("Enter the numbers:\n"); for (i = 0;i < Count;i++){ scanf("%i", Nums); } return 0; } Thanks for any help
There is a mistake in your code. When you do :

  for (i = 0;i < Count;i++){    scanf("%i", Nums);}   


You put all your values in Nums[0] because Nums == &(Nums[0]). You should do :

  for (i = 0;i < Count;i++){    scanf("%i", &(Nums[i]));}   


However, even with this bug it runs fine on my computer (no crash). I compiled it with MSVC++ 6.0.

The matter may be that you use %i for long int. Since it works fine with my compiler, I can only guess.

Try to add a printf( ...) just after the scanf("%i", &Count); to see if it gets the right value.
Advertisement
I actually had the in my origional code, I forgot to include it in the minimal version I posted. However, I did not have the &(...) I''ll try it that way when I get home...hopefully it will fix the problem. Thanks!

~RS

This topic is closed to new replies.

Advertisement