J
jeremy targett
Hello, in my program I use 2-dimensional arrays to hold two integer values
for each of i members of a list. array[0] holds a starting
position, and array[1] holds a label - in fact I #defined START as 0
and LABEL as 1 so I can just write
array[START] = whatever
array[LABEL] = whatever
(I declared array like this:
int array[MAXLENGTH][2];
)
I want to compare two arrays to see which is "best", first by comparing
the START values (at the first difference, the lower one is better), then
the LABEL values for each member (same rule). So I made a function
"arraycmp" which I invoke with the two arrays and a length. The function
should return <0 if the first array is better, >0 if the second array is
better, and 0 if they are the same. Here's my function:
arraycmp(int T[][], int S[][], int len)
{
int i;
for (i=0;i<len;i++)
if (T[START] != S[START])
return (T[START]-S[START]);
for (i=0;i<len;i++)
if (T[LABEL] != S[LABEL])
return (T[LABEL]-S[LABEL]);
return 0;
}
When I compile my program, gcc says this:
invalid use of array with unspecified bounds
Could someone tell me how to fix this please? Many thanks --Jeremy
for each of i members of a list. array[0] holds a starting
position, and array[1] holds a label - in fact I #defined START as 0
and LABEL as 1 so I can just write
array[START] = whatever
array[LABEL] = whatever
(I declared array like this:
int array[MAXLENGTH][2];
)
I want to compare two arrays to see which is "best", first by comparing
the START values (at the first difference, the lower one is better), then
the LABEL values for each member (same rule). So I made a function
"arraycmp" which I invoke with the two arrays and a length. The function
should return <0 if the first array is better, >0 if the second array is
better, and 0 if they are the same. Here's my function:
arraycmp(int T[][], int S[][], int len)
{
int i;
for (i=0;i<len;i++)
if (T[START] != S[START])
return (T[START]-S[START]);
for (i=0;i<len;i++)
if (T[LABEL] != S[LABEL])
return (T[LABEL]-S[LABEL]);
return 0;
}
When I compile my program, gcc says this:
invalid use of array with unspecified bounds
Could someone tell me how to fix this please? Many thanks --Jeremy