Your two bugs are here:
>while (fscanf(input_file_ptr;"%d", &newest)==1)
And here:
>else (values[0]> values[1])
The first bug is easily fixed by changing the semicolon after input_file_ptr to a comma and the second by either removing the test or changing the else to an else if.
Personally, I think you're making this way too complicated. Just keep two survivor variables and at the end of the program, they will contain the largest and second largest values:
Code:
#include <stdio.h>
int main ( void )
{
int largest = 0,
nextLargest = 0,
rawVal;
char buffer[BUFSIZ];
printf ( "Enter a series of integers (CTRL+Z to quit)\n$ " );
while ( fgets ( buffer, sizeof buffer, stdin ) != NULL ) {
if ( sscanf ( buffer, "%d", &rawVal ) == 1 ) {
if ( rawVal > largest ) {
nextLargest = largest;
largest = rawVal;
}
else if ( rawVal > nextLargest )
nextLargest = rawVal;
}
else
(void)puts ( "Invalid integer" );
printf ( "$ " );
}
printf ( "The largest value is: %d\n"
"The next largest is: %d\n", largest, nextLargest );
return 0;
}
This can easily be converted to read from a file instead of standard input.
-Prelude