Am I right in assuming this is a school assignment?
It would make sense to parse the file line by line (I assume the file is plain text, not binary?).
This can be done using old-fashioned readln(filevar, stringvar) or in modern dialect (as in: fpc, delphi) use a TStringList and load the file in one read, then parse all lines.
If you knew the size of the matrix you could use
readln(matrixfile, val1, val2, val3); //val1 etc of type Real
But since you don't, read each line as a string, then parse the string into the values.
For that you need to run through the string, stop at each space (#32) and parse that piece of the string.
This is teadious work, and again TStringList can do that for you (see TStringList.DelimitedText).
I don't know if you are allowed to use things like TStringList or functions like StrToFloat that would make this task that much easier.
If not you will have to write some functions to do so yourself
So processing a file:
- Read first line: it contains size of Matrix
- repeat size times: read next line, parse line
- make sure you can handle invalid files (non-exsting file, too many or too little lines, invalid value for size etc.)
An observation:
function Madd(A,B : TMatrix; sizeI,sizeII: integer):Tmatrix;
It does not return the size of the calculated matrix.
Maybe this is not needed because you know it before the calculation already?
So try to write code that can read a matrix from a file and come back here.
Once you've got that, you're almost done: just sticking the pieces together.
Last piece of advice: include some sort of error handling for the reading of the matices.
You don't want to let invalid input crash you program.
Especially for manual input it is IMO not acceptable that the user gets punished for one false keystroke (I would throw away my keayboard, curse you and maybe hire a hitman, if I mistyped something in the last value of matrix B with both sized 20x20 and the program crashed).
(If this program was for the real world, I would also give the user the ability to abort the program while entering values.)
For file reading, it is acceptable IMO to stop the program (in a nice way, telling the user why) if a non-valid file was presented.
Bart