Error unknown type name

0

I'm trying to pass a typedef struct as a parameter to a function but gives the error: "bib.h: 6: 13: error: unknown type name 'array'" 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 bib.h library:

#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 the struct in function! Just testing a few things.

    
asked by anonymous 08.12.2014 / 22:01

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.h file

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.c file

#include "bib.h"

int main(){
    Matriz matriz;
    gerarMatriz(matriz);
    return 0;
}
    
08.12.2014 / 22:43