I need help finding the appropriate way to provide values to my function in C which can be seen below:
void matrixMultiply(int *A[], int *B[])
I have the following function that needs 2 pointer to arrays, and those pointers point to two 2d arrays. I have the following main function, but I just can't seem to figure out a way to pass my arrays to the function.
int main()
{
int arr[2][2] = {
{ 1, 2 },
{ 5, 6 }
};
int(*p)[2];
p = &arr;
int arr2[2][1] = {
{ 11 },
{ 55 }
};
int(*l)[1];
l = arr2;
for (int i = 0; i < 4; i++) // I don't know if I need this but I used it before when I was experimenting with the form p[i].
{
matrixMultiply(p, l); // p and l are the pointers to the two 2d arrays I have
}
return 0;
}
This is the updated code:
int main()
{
int arr[2][2] = {
{ 1, 2 },
{ 5, 6 }
};
int(**p);
p = &arr;
int arr2[2][1] = {
{ 11 },
{ 55 }
};
int(**l);
l = arr2;
for (int i = 0; i < 4; i++) // I don't know if I need this but I used it before when I was experimenting with the form p[i].
{
matrixMultiply(p, l); // p and l are the pointers to the two 2d arrays I have
}
return 0;
}
C:\WINDOWS\system32\cmd.exe /C ""C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" -j12 SHELL=cmd.exe -e -f Makefile"
C:/Users/Owner/Desktop/Codes/aee22eeCodes/main.c: In function 'main':
C:/Users/Owner/Desktop/Codes/aee22eeCodes/main.c:49:16: warning: passing argument 1 of 'matmul' from incompatible pointer type [-Wincompatible-pointer-types]
matmul(&arr, &arr2); // p and l are the pointers to the two 2d arrays I have
^~~~
C:/Users/Owner/Desktop/Codes/aee22eeCodes/main.c:12:18: note: expected 'int **' but argument is of type 'int (*)[2][2]'
void matmul(int *A[], int *B[])
~~~~~^~~
C:/Users/Owner/Desktop/Codes/aee22eeCodes/main.c:49:22: warning: passing argument 2 of 'matmul' from incompatible pointer type [-Wincompatible-pointer-types]
matmul(&arr, &arr2); // p and l are the pointers to the two 2d arrays I have
^~~~~
C:/Users/Owner/Desktop/Codes/aee22eeCodes/main.c:12:28: note: expected 'int **' but argument is of type 'int (*)[2][1]'
void matmul(int *A[], int *B[])
~~~~~^~~
====0 errors, 4 warnings====