>>The key here is to have something efficient because the files the grader will be using are huge.
If you know the format of the file and it's consistent then you can fake indexed access and get great performance by treating i and j as offsets. For example, in a file like this
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
You could add each of those numbers like this :-)
Code:
#include <stdio.h>
int main(void)
{
FILE *fp;
int a = 0, b = 0;
long i = 2L, j = 3L; /* Test values */
if ((fp = fopen("input.txt", "rb")) == 0)
{
return 1;
}
if (fseek(fp, i * 2, SEEK_SET) != 0 || fscanf(fp, "%d", &a) != 1)
{
return 1;
}
if (fseek(fp, j * 2, SEEK_SET) != 0 || fscanf(fp, "%d", &b) != 1)
{
return 1;
}
printf("%d + %d == %d\n", a, b, a + b);
fclose(fp);
return 0;
}