# Thread: error C2087: '<Unknown>' : missing subscript

1. ## error C2087: '<Unknown>' : missing subscript

'initializing' : 'int ' differs in levels of indirection from 'void *'
error C2087: '<Unknown>' : missing subscript
warning C4013: 'malloc' undefined; assuming extern returning int
warning C4047: 'return' : 'int ' differs in levels of indirection from 'int *'

does anybody know what could be wrong, i checked everything....
Code:
```int main()
{
int sranje;
int matrica[100][100]={NULL};
int st, re,i,j;
printf("ST: ");
scanf("%d", &st);
printf("RE: ");
scanf("%d", &re);
for(i=0;i<st;i++)
{
for(j=0;j<re;j++)
{
printf("%d.%d = ",i+1,j+1);
scanf("%d", &matrica[i][j]);
}
}
for(i=0;i<re;i++)
{
printf("%d", funk(matrica,st,re));
}
scanf("%d", &sranje);
}
int funk(int matrica[][], int st, int re)
{
int *niz;
int i,j,sum=0;
niz=((int *)malloc(sizeof(int)*(re)));
for(i=0;i<st;i++)
{
for(j=0;j<re;j++)
{
sum=sum+matrica[i][j];
niz[i]=sum;
if(j==st)
{
sum=0;
}
}
}
return niz;
}```

2. Add "#include <stdlib.h>" would be a good start.

You may want a prototype for "funk" too. And it returns "niz" which is a pointer to int, but you declare the function as "int funk(...)".

You should alse free the return from funk at some point.

--
Mats

3. nothing, wont work....i tried without pointers and malloc, with fixed size array, nothing...

4. Ehm, I don't think you understood my comments.

You need to give the compiler a clue as to what malloc does, which is to include stdlib.h

If you allocate memory, you will need to give it back by calling free.

By the way, your first error mesage is to do with this line:
Code:
`	int matrica[100][100]={NULL};`
You are initializing a twodimensional array to NULL - NULL is a pointer, not an integer, so the compiler decides that this is not a valid initialization.

And I presume that your "funk" is supposed to return an array, in which case you can't return a single integer value.

--
Mats

5. I'm not even using malloc anymore, not returning anything im printing output inside of function, things like this worked before without problem....this is stupid!

Code:
```int funk(int matrica[][], int st, int re)
{
int niz[50];
int i,j,sum=0;
for(i=0;i<st;i++)
{
for(j=0;j<re;j++)
{
sum=sum+matrica[i][j];
niz[i]=sum;
if(j==st)
{
sum=0;
}
}
}
for(i=0;i<re;i++)
printf("%d", niz[i]);
}```

6. Originally Posted by shardin
I'm not even using malloc anymore, not returning anything im printing output inside of function, things like this worked before without problem....this is stupid!

Code:
```int funk(int matrica[][], int st, int re)
{
int niz[50];
int i,j,sum=0;
for(i=0;i<st;i++)
{
for(j=0;j<re;j++)
{
sum=sum+matrica[i][j];
niz[i]=sum;
if(j==st)
{
sum=0;
}
}
}
for(i=0;i<re;i++)
printf("%d", niz[i]);
}```
I don't see anything wrong with that function. Describe what you mean by "not working anymore"?

--
Mats

7. Code:
`int funk(int matrica[][], int st, int re)`
You can't declare a multidimensional "array" as a function parameter without specifying the size of all dimensions except left-most.

As an alternative you may consider int ** matrica.

8. Code:
`int funk(int matrica[][100], int st, int re)`
When passing a multidimensional array in this manner, only the first dimension can be omitted.

9. Originally Posted by hk_mp5kpdw
Code:
`int funk(int matrica[][100], int st, int re)`
When passing a multidimensional array in this manner, only the first dimension can be omitted.
Yes, of course. I so rarely pass 2D arrays around that I forget those little details.

--
Mats