Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When running a C language program with vscode, it keeps reporting an error, but it can generate the correct executable file. What's the matter?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

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);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading