Question re: Pointers (I think)

This relates to an assignment, but I am not looking for answers (read the FAQ on that!)

I have written a program to multiply matrices, however, now that I re-read the specifications, I have a question.

I am supposed to implement a function as follows
void matmult(int m, int p, int n, float **a, float **b, float **c)

Well, I have a function like this:
void matmult(int m, int p, int n, float *a, float *b, float *c)

I've fiddled around with this thing, read plenty of articles, and searched, but I cannot grasp these pointers and other assorted nuances of C++. This is only my second program to write in the language and I'm a bit befuddled.

The algorithms are done, the program runs, I just need some nudges in the right direction regarding the function declaration.

Thanks,
Steve
Additionally, here is my code. Please feel free to rip it to pieces as I'm still new at C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <cstdlib>
#include <iostream>
using namespace std;

void matpop(int m, int n, float *matToPop) {
    int i, j;
    float tempFlt = .0f;
    for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
            tempFlt = i * n + j;
            matToPop[i * n + j] = tempFlt;
        }
    }
}

void matmult(int m, int p, int n, float *a, float *b, float *c) {
    int i, j, k;

    for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
            float tempFlt = .0f;
            for (k = 0; k < p; k++) {
                tempFlt += a[i * p + k] * b[k * n + j];
            }
            c[i * n + j] = tempFlt;
        }
    }
}

void matprint(int m, int n, float *outputMat) {
    int i, j;
    for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
            float tmp = outputMat[i * n + j];
            cout << tmp << "\t";
        }
        cout << "\n";
    }
    cout << "\n";
}

int main(int argc, char** argv) {

    int m, p, n;
    cout << "Please enter the number of rows in array A: ";
    cin >> m;
    cout << "Please enter the number of columns in array A: ";
    cin >> p;
    cout << "Please enter the number of columns in array B: ";
    cin >> n;

    float a[m * p];
    float b[p * n];
    float c[m * n];

    matpop(m, p, a);
    matpop(p, n, b);

    matmult(m, p, n, a, b, c);

    cout << "The values for matrix A are:\n";
    matprint(m, p, a);
    cout << "The values for matrix B are:\n";
    matprint(p, n, b);
    cout << "The values for matrix C are:\n";
    matprint(m, n, c);

}
I cannot grasp these pointers


Check out

http://www.cdecl.org/

Its a website that translates c++ declarations into english. It's very useful for deciphering pointers.
Topic archived. No new replies allowed.