Question: Create An Array Of 6x8 And Read Each Number Into The Array With The Following: Read Each Number Into One Dimension Of The Array Until

Create An Array Of 6x8 And Read Each Number Into The Array With The Following: Read Each Number Into One Dimension Of The Array Until You Hit 0 Then Move To The Next Set Example: After You Have Read The Numbers Into The 2-Dimensional

Create an array of 6x8 and read each number into the array with the following: read each number into one dimension of the array until you hit 0 then move to the next set Example:

After you have read the numbers into the 2-dimensional array totally, then sum them up and print out the sum

I have already written some code:

#include

int main(void){

char *file_name = \"\";

FILE *fptr = fopen(file_name, \"r\");

if(fptr == NULL){

printf(\"Error\");

return 1;

}

// declare the 2 dimensional array

int num;

int i = 0, j = 0;

while (fscanf(fptr, \"%d\", &num) == 1) {

// put the number in the array

if (num != 0) {

arr[i][j++] = num;

}

else {

arr[i++][j] = num;

j =0;

}

fclose(fptr);

}

int total_rows = i;

int sum = 0;

for (int i = 0; i

for (int j = 0; j

if (arr[i][j] != 0) {

sum += arr[i][j];

}

else {

//print the sum

sum = 0;

break;

}

}

}

return(0);

}

The txt file looks something like this:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!