Unknown error type name

Asked

Viewed 3,158 times

0

I’m trying to pass a typedef struct as a parameter to a function, but it gives the error: "Bib. h:6:13: error: Unknown type name 'matrix'" Here is the code:

#include "bib.h"

typedef struct
{
    int matriz[N][N];
}matriz;

void gerarMatriz(matriz m);

int
main()
{   
    matriz m1;

    gerarMatriz(m1);

    return(0);
}

And the library Bib. h:

#include <stdio.h>

#define N 5

void
gerarMatriz(matriz m)
{
    int i;

    for(i = 0; i < N; i++)
    {
        printf("%d\n", (1 + rand() % 20));
    }
}

I’m still not doing anything with struct in function! Just testing a few things.

1 answer

2


In Bib. h it does not recognize this variable matriz because it was created in the first file. You would need to make a #include "main.c" of the first file or else create your struct inside the Bib file. h

For example, the Bib. h file:

#include <stdio.h>
#define N 5

typedef struct {
    int matriz[N][N];
} Matriz;

void gerarMatriz(Matriz matriz){
    int i;
    for(i = 0; i < N; i++)
        printf("%d\n", (1 + rand() % 20));
}

And the main file. c

#include "bib.h"

int main(){
    Matriz matriz;
    gerarMatriz(matriz);
    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.