1

newUpdate: seems to work now

updated:

OK, so this is my declared 2d array:
int data[10][20];

It's filled up with variables as such:
k=0; token = strtok (str," "); while (token != NULL) { sscanf (token, "%d", &var); data[k++][i] = var; token = strtok (NULL," "); }

So we expect data[0-9][i] for each i. Then we find the index we need to use

data[0-9][j]

case 2:
    prinf("What experiment would you like to use?\n");
    token = strtok (NULL," ");
    sscanf (token, "%s", &str2);
    for(j=0;j<i;j++)
    {
        if(strcmp(experiments[j],str))
        {
            indAvg = individualAverage(data,j);
            printf("The individual average of %s is %d\n",experiments[j],indAvg);
            break;
        }
    }

Which is meant to call this:

int individualAverage(int data[][20],int j)
{
    int k,average=0;
    for(k=0;k<10;k++)
    {
        average += data[k][j];
    }
    return average;
}

The problem I'm getting is that it says in my individualAverage function, the 'array type has incomplete element type'. In my call to the function, it says 'type of formal parameter 1 is incomplete'.

I'm not sure what I'm doing wrong here?

Thanks.

user3251142
  • 175
  • 6
  • 15
  • possible duplicate of [passing dynamic 2D arrays to function](http://stackoverflow.com/questions/5711268/passing-dynamic-2d-arrays-to-function) – givanse Mar 09 '14 at 15:06
  • Also: http://stackoverflow.com/questions/14012020/how-to-pass-a-2d-array-through-pointer-in-c – givanse Mar 09 '14 at 15:07

1 Answers1

3
int individualAverage(int data[][],j)

You are missing data type for j. You also need to pass in the size of the 2d array by at least specifying the column length

int individualAverage(int data[][COL_LENGTH],int j)
LeatherFace
  • 468
  • 2
  • 10
  • I made a mistake. The size of data is declared in the beginning as: `int data[10][20];` I know that there are definitely 10 integers in the first [10], but I'm not sure how many sets of these 10 integers there will be. that's where `int j` comes into play. So how exactly do I declare it in this case? – user3251142 Mar 09 '14 at 14:53
  • @user3251142: Please update the question to include the crucial information about the declaration of the array (which should, ideally, have been there from the start). You'll need to clarify what you mean about there only being 10 integers in use. The type of the array — and the correct form for the parameter declaration — depends on the type of the array, not on the number of values in use. – Jonathan Leffler Mar 09 '14 at 14:56
  • When passing it into your function you still need to pass in the column length. – LeatherFace Mar 09 '14 at 14:57