Bad check of value in your way.
For example, like this
#include <stdio.h>
#define EOI -1 //End Of Input
int main(void){
int input, first, second;
first = second = EOI;
while(1){
if(1 != scanf("%d", &input)){
fprintf(stderr, "invalid input!\n");
return -1;
}
if(input == EOI)
break;
if(first == EOI){
first = input;
} else if(first <= input){
second = first;//slide
first = input;
} else if(second == EOI || second < input){
second = input;
}
}
if(second == EOI){//first == EOI || second == EOI
fprintf(stderr, "No valid value is entered more than one!\n");
return -2;
}
printf("%d\n", second);
return 0;
}
solved Find second highest number without using array [duplicate]