Creating variable-size arrays

This is a discussion on Creating variable-size arrays within the C Programming forums, part of the General Programming Boards category; I'm writing a program in C to multiply two user-inputted matrices and am having a little bit of trouble initializing ...

Creating variable-size arrays

I'm writing a program in C to multiply two user-inputted matrices and am having a little bit of trouble initializing the input arrays...

Basically, the program starts with the user inputting the dimensions of each matrix (matrix1 and matrix2) and then these values are stored as integers in the variables rowsize1, columnsize1, rowsize2, columnsize2.

I now want create these two matrices... However I cannot do this with matrix1[rowsize1][columnsize2] and matrix2[rowsize2][columnsize2] as this is illegal in C!

I read that variable-size arrays can be created in C by using the "malloc" function but I'm not entirely sure on how to implement it in my case...

For the first matrix (matrix1) would I have to do something like this:

Thanks a lot for that! It works perfectly now!
Here is my complete code....

Just to clarify, this method of creating a variable-size array is a new feature in the C99 standard, right? Therefore, there is no way to compile this on Microsoft Visual C (I receive numerous errors when I try to)?

Since you are using Visual Studio, you can let it fix your indentation (select all, alt+f8), and you can also look into safe functions such as scanf_s. And you're right. Visual Studio doesn't support C99, unfortunately.