Hey everyone, I have a kind of large problem.

I am trying to input something in C, a number between 0 and 50,000, using scanf(). I understand how scanf generally works, and it does for the most part, but for some reason if the number I enter is greater than 37504, the program just stops. Doesn't freeze, doesn't crash, just stops. I have tried changing the data type from int, and have tried unsigned int and long int as well, any other suggestions about what's going on? Thanks!

Here's the pertinent part of code:

int main ()

{long int max;


printf("Enter an integer between 2 and 50,000: ");
scanf("%ld", &max);

etc.

Edited 6 Years Ago by WaltP: Fixed CODE tags. There IS a Preview button. And an Edit button. You can use them both.

why do you define your int like this

long int &max;

with the "&"...

Don't you mean

long int max;

Edited 6 Years Ago by gerard4143: n/a

By stop do you mean the program exits?

You really should try running your code with a debugger...

If you not comfortable running a debugger then place a printf right after the scanf
and check the value of max

printf("Enter an integer between 2 and 50,000: ");
scanf("%ld", &max);
printf(check value of max);

Edited 6 Years Ago by gerard4143: n/a

I'm using Visual so I have a debugger, but there are no warnings or errors. printf is returning the correct value;

When I say it stops, it acts as if there is no more code, but does not exit because I have a getchar() placed at the end.

AH, I figured it out, it wasn't the scanf after all, it was a loop afterward, a pretty bad logic error. Thanks guys!

Here's the pertinent part of code:

Do yourself and everyone else a big favor: post actual code, not a "pertinent" version. You already demonstrated that you introduce separate errors in doing so.

Trim your code into a separate, smaller snippet if you choose. But post actual code that compiles and demonstrates the issue.

This question has already been answered. Start a new discussion instead.