Question: A function that will read the data file name and its contents. The first row of the data file will have two entries: the number

 A function that will read the data file name and itscontents. The first row of the data file will have two entries:the number of rows in the matrix followed by the number of

A function that will read the data file name and its contents. The first row of the data file will have two entries: the number of rows in the matrix followed by the number of columns in the matrix, the remainder of the file will contain the (real, floating point) matrix elements, row by row. The function should return the number of rows and columns in the matrix as well as the matrix.

I'm stuck on how to scan in the data. I feel like I would be able to do the rest if I got some help on the first function. This is my attempt:

double function1(void)

{

char filename[20];

double matrix[5][5], row, col, rowcol[2];

int status, i, j;

FILE* infile;

printf("Enter the file name: ");

scanf_s(" %s", &filename);

infile = fopen(filename, "r");

//error check filename

while (infile == NULL)

{

printf(" The file doesn't exist. ");

printf("Enter the file name: ");

scanf_s(" %s", filename);

}

//read data in

fscanf_s(infile, "%lf %lf", &row, &col);

for (i = 0; i

{

j = 0; // what is =0 here

for (j = 0; j

{

fscanf_s(infile, "%lf", &matrix[i][j]);

printf("matrix[%d][%d] = %lf", i, j, matrix[i][j]);

}

}

fclose(infile);

rowcol[0] = row;

rowcol[1] = col;

return(rowcol[2]);

}

Engr 0012: Introduction Engineering Computing Programming Assignment 16 Tuesday April 19 aware project developing Problem: You have hired by Inc as a new sof MATLAB developing a new product that it hopes will rival and charge of team in engineering tool for design and analysis. You have been assigned to the development the matrix handling portion of the software package. round of Background: The basic matrix operati that you need to perform in this first Matrix addition: where cu au same dimensions note: matrix addition is only permitted ifIA] and [Bj have the a warning should be displayed if the addition cannot be performed Matrix subtraction: ,w where cu au dimensions note: matrix subtraction is only permitted if [A] and [B] have the same a warming should be displayed if the subtraction cannot be performed Matrix multiplication: car 4M,NLBAP note: matrix multiplication is only permitted if[BN,P has the same number of rows as [Altar has columns. The resulting matrix has dimension MxP a warning should be displayed if the multiplication cannot be performed Matrix element by element multiplication: P [Al.N[Bl, where cy au note: by element multiplication is only permitted if BlNxP has the same number of and columns as [A]MaN a warning should be displayed if the multiplication cannot be performed Assignment: Design and code acprogram that has the following functions: a) A function that will read the data file name and its contents. The first row of the data file have two entries: the number of rows in the matrix followed by the number of columns in the matrix, the remainder the file will contain the (real, floating point matrix elements, row by row. The function should return the number of rows and columns in the matrix as well as the matrix What does this function need from the calling function to do its job? (nothing why? What does this function need from the user to do itsjob? thing what? What will the function retum to the calling program, if successful

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 Databases Questions!