C中很经典的异常,某公司的面试题

C中很经典的错误,某公司的面试题
以下程序我已经经过修改,提出主要部分,大家可以尽情猜解,为什么会死循环?
void   main()
{int   g,s,b,q,w,a,k;
  /*g表示换位后的个位数,s表示换位后的十位数,b,q,w,同理分别表示换位后的百,千,万位数。a表示输入数的位数*/
  long   int   u,n;   /*u表示要输入的数,n表示换位后的数。*/
 
loop:
  printf( "请您输入一个不超过5位的数字:\n ");
  scanf( "%d ",&u);

    if((u> 0)&&(u <100000)){
                  //do   something
        }
    else   {k=0;
                printf( "您输入的不是数字或输入数字超出范围!\n ");
                        printf( "请您重新输入:\n ");
goto   loop;
                        }
}

输入非数值问题会死循环,请问为什么!?

------解决方案--------------------
每次都输入非数值,当然会死循环了。不过如果输入是一个字符,应该也不会
------解决方案--------------------
没人解答啊,都不懂吧,高手呢?

------解决方案--------------------
貌似scanf应该用%ld
还有,那个k是干什么用的
------解决方案--------------------
The scanf function scans each input field, character by character. It may stop reading a particular input field before it reaches a space character for a variety of reasons:

The specified width has been reached.

The next character cannot be converted as specified.

The next character conflicts with a character in the control string that it is supposed to match.

The next character fails to appear in a given character set.

For whatever reason, when the scanf function stops reading an input field, the next input field is considered to begin at the first unread character. The conflicting character, if there is one, is considered unread and is the first character of the next input field or the first character in subsequent read operations on the input stream.

------解决方案--------------------
The scanf function scans each input field, character by character. It may stop reading a particular input field before it reaches a space character for a variety of reasons:
scanf函数一个字符一个字符地扫描每一个输入,在下列各种情况下输入空格之前,它会停止
读取那个特定的输入域:

The specified width has been reached.
当达到指定宽度时

The next character cannot be converted as specified.
当下一个字符不能如期转换时

The next character conflicts with a character in the control string that it is supposed to match.
下一个字符与控制字符串中相匹配的字符冲突

The next character fails to appear in a given character set.
下一个字符不能出现在给定集合中

For whatever reason, when the scanf function stops reading an input field, the next input field is considered to begin at the first unread character. The conflicting character, if there is one, is considered unread and is the first character of the next input field or the first character in subsequent read operations on the input stream.
不论什么原因,当scanf函数停止读一个输入域的时候,下个输入域被考虑从第一个没有读取的字符开始。如果有字符冲突, 是下一个域的第一字符或在输入流上的后续读取操作的第一个字符,将被视为不可读取的

------解决方案--------------------
printf( "请您输入一个不超过5位的数字:\n ");
scanf( "%d ",&u);
这两行的代码应该连在一起看才是。
其实程序在运行的过程中,就是不输入数据也一样可以正常运行的。
这个原因就是scanf函数的特殊的特性造成了。
------解决方案--------------------
这个问题并不是在每个机器上都会出现的。有的机器可能会死循环。