简体   繁体   中英

How to pass 2d array into c program?

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM