Matrix Multiplication ( Accessing data from a file ) HELP

HI I am a new c programmer, working on a program that multiplies matrices.

the program is suppose to read number from a file,

The first line of a file contains an integer number, say n. This number is then followed by 2n rows of integer numbers. Each row contains n integer numbers. The first n rows of numbers represent the values in a matrix A. The second n rows of numbers represent the values of the matrix B. Matrix A and matrix B are both n x n . Write a C progam that will multiply these two matrices together forming a result matrix that is also n x n. The value of n will not be greater than

50. file comes in through argv[1].

The puzzling part of this problem is how am i going to read the first line from the file and malloc up space for the matrix? secondly, if the first line of my file is the dimensions of my matrix, please tell me what c function can be used to read the first line of my file for the matrix dimension and then reads the next subsequent lines as data for my matrix.

Any suggestions would be greatly appreciated!

Thankyou!