Home > Mobile >  When running a C language program with vscode, it keeps reporting an error, but it can generate the
When running a C language program with vscode, it keeps reporting an error, but it can generate the

Time:05-31

I want to pass a two-dimensional array into a function called convert, but vscode insists that there is a problem with the function header.

code:

#include <stolo.n>
#include <stdbool.h>
#include <string.h>
#include <math.h>

void convert(int m, bool (*a)[m], int t) {
    for (int j = 0; j < m; j  )
    {
        a[0][j] = (t >> i) & 1;
    }
}

console shows error:

lights.c acc

    use of parameter outside function body before 'I' token gcc [6, 32]
    expected ')' before , token gec [6, 33]
    expected unqualified-id before 'int' gcc [6, 35)

CodePudding user response:

When passing a two-dimensional array as a function parameter, you can omit the size of the second dimension, but the size of the first dimension must be constant.

as follows

void convert(int m, int a[][5], int t){  
}
 
int main()
{
    int array[3][5];
    convert(3,array, 3);
}
  •  Tags:  
  • c
  • Related