$ cp -r ~steve/ex/mda .
Implement the function read_array in array.c. It should read in a rectangular (2D) array of integers from the specified file into an array and return the array along with the number of rows and columns. See array.h and array.c for details.
read_array
array.c
array.h
The first line of the file contains two integers: the number of rows and the number of columns. Following this are number-of-rows lines each of which contains number-of-columns integers. For example,
5 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
represents a 2D array with 5 rows and 3 columns (this file is in small.txt) (123456789101112131415).\begin{pmatrix}1&2&3\\4&5&6\\7&8&9\\10&11&12\\13&14&15\end{pmatrix}.⎝⎜⎜⎜⎜⎛147101325811143691215⎠⎟⎟⎟⎟⎞.
small.txt
write_array
copyarray
$ make copyarray
copy.txt
$ ./copyarray small.txt copy.txt
Check that the output matches what you expect.
Implement the missing functionality in transpose.c. It should take in an array from one file, compute the transpose, and write it out to the second file.
transpose.c
The transpose of the small 5×35\times 35×3 array above is the 3×53\times 53×5 array (147101325811143691215).\begin{pmatrix}1&4&7&10&13\\2&5&8&11&14\\3&6&9&12&15\end{pmatrix}.⎝⎛123456789101112131415⎠⎞.
Create a new program matrixmult (and add it to the Makefile by adding matrixmult to the bins variable) with a corresponding matrixmult.c This program should take three arguments. The first two should be the paths to files containing arrays and the third is the output file. Compute the matrix multiplication of the two input arrays and write the result to the output file.
matrixmult
Makefile
bins
matrixmult.c
Note that if you have a k×mk\times mk×m matrix and a m×nm\times nm×n matrix, then the result of multiplication is a k×nk\times nk×n matrix. Otherwise, the multiplication isn’t defined.