-
Reading data from a file
Hi,
Can someone please explain me the following code I don't understand the question.
Thanks
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/**
Source: q1.c
--------------
Write a program in C to do the following.
For each of the three datasets in input1.txt
Read integer n
Read n integers and add them up.
Write the sum of the n integers to stdout (no words, just the sum).
---------------------------------------------------
EXPECTED OUTPUT:
6
30
417
*/
int main (void)
{
int i, j, n, sum, value ;
FILE * inp ;
inp = fopen("input1.txt", "r") ;
if (inp == NULL) {
printf("Could not find input file: input1.txt\n") ;
exit(1) ;
}
//----------------Start below here. To do: approximate lines of code = 9
// 1. See instructions above.
//----------------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
exit(0) ;
}
-
The input file:
3
1 2 3
2
14 16
10
15 13 10 3 18 4 15 17 100 222