ok, now I understand. You've copy&pasted code for file processing and don't really understand how it works.
Code:
this code reads 1 integer:
fscanf(numbers, "%d", &a);
and this code reads 5 integers at once:
fscanf(numbers, "%d %d %d %d %d", &a, &b, &c, &d, &e );
You see the pattern here, right?
Aww what the hell I'll just write and comment it:
Code:
#include <stdio.h>
#include <stdlib.h>
#define NUMBERS_YOU_HAVE_TO_READ 5
int main(void)
{
int a, n, smallest, largest;
FILE *numbers, *results;
numbers = fopen("data.txt","r");
results = fopen ("results.txt","w");
fscanf(numbers, "%d", &a); // Reading 1 integer from input file
smallest = largest = a; // Setting smallest and largest to number readed
n = 1; // Setting n to 1
while (n < NUMBERS_YOU_HAVE_TO_READ) // Looping while n is less than whatever
{
fscanf(numbers, "%d", &a); // Reading 1 integer from input file
if (a < smallest) // Comparing it with smallest
smallest = a; // and correcting if needed
if (a > largest) // Comparing it with largest
largest = a; // and correcting if needed
n++; // Incrementing n. Equivalent to n = n + 1;
}
// Writing output to output file
fprintf ( results, "smallest is %d\n", smallest);
fprintf ( results, "largest is %d\n", largest);
// Cleanup
fclose(results);
fclose(numbers);
return 0;
}
And don't just copypaste it! Write it again and try to understand and memorize.