Lets say I am reading a file with 2 lines of numbers. Forexample lets say that t
ID: 3617443 • Letter: L
Question
Lets say I am reading a file with 2 lines of numbers. Forexample lets say that the lines are:2 2 2 2 1 1 1 2
I understand how I would read these lines from a file andstore them into an array...
for(i = 0; i < 4; i++) fscanf(*fpt, "%d", first[i]);
and I understand how I would read the second line...
for(j = 0; j < 4; j++) fscanf(*fpt, "%d", second[i]);
What I need to know is how I would go about adding the 2corresponding values in the arrays. Would I create a third array? third[4] = first[i] +second[j]?
I'm sure that isn't correct, but that is essentially what Ineed. so that when I print out the third array I would get: 33 3 4
2 2 2 2 1 1 1 2
I understand how I would read these lines from a file andstore them into an array...
for(i = 0; i < 4; i++) fscanf(*fpt, "%d", first[i]);
and I understand how I would read the second line...
for(j = 0; j < 4; j++) fscanf(*fpt, "%d", second[i]);
What I need to know is how I would go about adding the 2corresponding values in the arrays. Would I create a third array? third[4] = first[i] +second[j]?
I'm sure that isn't correct, but that is essentially what Ineed. so that when I print out the third array I would get: 33 3 4
Explanation / Answer
please rate - thanks #include #include int main() {int i, first[4],second[4],third[4]; FILE *fpt; if(!(fpt=fopen("input.txt","r"))) { printf(" Error opening input.txt "); getch(); return 1; } for(i = 0; i < 4; i++) fscanf(fpt, "%d", &first[i]); for(i= 0; i < 4; i++) fscanf(fpt, "%d", &second[i]); for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.