这段代码真的能将开头为非数字的整行输入丢弃吗?为什么跑出来的结果还是不对的?

图片说明图片说明图片说明

#include <stdio.h>
#include <stdlib.h>
#define N 5
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    long input;
    char ch;
    while(scanf("%ld",&input)!=1)
    {
        while((ch=getchar())!='\n')
             putchar(ch);
    }
    printf("%ld",input); 
    return 0;
}

可以啊

#include <stdio.h>
#include <stdlib.h>
#define N 5
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
    long input;
    char ch;
    while(scanf("%ld",&input)!=1)
    {
        while((ch=getchar())!='\n')
             ;//putchar(ch); //这里的输出只是告诉你你输入了什么,实际使用应该去掉
    }
    printf("%ld",input); 
    return 0;
}

图片说明