trouble converting 1-D array into 2-D

I have a program for finding the grades in a class of 10 students that uses 1-D arrays. My code is posted below. How do I convert it into 2-D array? Below the code, I gave an example of how I tried to do it, but I don't think I'm going about it right. Please help!

For each function, I changed the for loop to a nested for loop. For example, for the function calculateQuizzes, I changed it to:[code]float calculateQuizzes (float q[][]){ float sum = 0; for (int r = 0; r < 10; r++) for (int c = 0, c < 5; c++) sum += q[r][c]; return (sum/100) * 10;}[/code]...and then up in the function declarations above the main, I changed it to "float calculateQuizzes (float[][]);". But there's got to be more to it than that! What else do I need to do?

Comments

: I have a program for finding the grades in a class of 10 students : that uses 1-D arrays. My code is posted below. How do I convert it : into 2-D array? :Be aware that 2D arrays are rather an advanced feature of C. Most books introduce them along with 1D arrays, without mentioning the special problems they cause.

The central dicciulty is that a C array is just a buffer in memory. But when the array is 2D, the extra duimension information isn't stored anywhere. So you need to hardcode it in.

Things like

int foo2D(float parameter[][])

are illegal because foo2D has no way of knowing how many entries are in each row. However

int foo2D(float parameter[][3])

is OK.

The problem is that often your array dimensions aren't known at compile time. So 2D arrays can't be used at all, you have to fake them up from arrays of pointers, or simply treat as a 1D array and do the indexing calculations manually.

All of that is true. Before you start using multi-arrays, I'd advise you to make sure you know exactly how parameter passing to functions work, and exactly how dynamic memory allocation works.

Next thing you must be aware of is that multi-arrays in C is [italic]an abstract programming structure[/italic] and not a mathematical vector/matrix. Unless of course, you specify it that way when you create them.

To make things even more complicated and confusing, C supports many many ways to implement 2-d arrays. They all come with various advantages and disadvantages. You need to pick the one that suits your needs best.

Static multi-array:

[code]int array[x][y];[/code]

Advantages: Fast, safe, compatible with ISO functions like memcpy().Disadvantages: Dimensions can't be set or changed in runtime. Possibly eats a lot of static memory.

Static mangled multi-array:

[code]int array[x*y];[/code]

Advantages: Safe, uncomplicated, compatible with ISO functions like memcpy(). Compatible with 1-d arrays and functions accepting 1-d arrays.Disadvantages: Dimensions can't be set or changed in runtime. Possibly eats a lot of static memory. Somewhat slow access time since the index

Advantages: Dimensions can be set and changed in runtime. Easy to change the size of the outer dimension. Allocated on the heap.Disadvantages: Slow and unsafe. Not compatible with ISO functions like memcpy(), or with static multi-arrays.

Advantages: Dimensions can be set and changed in runtime. Easy to change the size of the outer dimension. Allocated on the heap. Compatible with ISO functions like memcpy() and with static multi-arrays.Disadvantages: Slow and unsafe. Complicated syntax. Turns messy when more than 2 dimensions are used.(As you can see, this version beats pointer-to-pointer in every way.)

Dynamic mangled multi-array:

[code]int* array;array = malloc(x*y);[/code]

Advantages: Dimensions can be set and changed in runtime. Allocated on the heap. Compatible with ISO functions like memcpy() and with static multi-arrays.Disadvantages: Slow and unsafe. Changing dimensions is inefficient.