Home > Software engineering >  Conflicting types for a struct
Conflicting types for a struct

Time:12-18

I have a homework where i have a codebase that i cannot modify, and i have to make a struct that has to be filled with a function. Here's the code, where the function fillDrivers() is from the codebase, the struct is made by me.

#include <string.h>
#include <stdbool.h>

void fillDrivers(Driver[]);

typedef struct{
    char name[20];
    char surname[20];
    int carNumber;
    bool rookie;
}Driver;

int main(void)
{
    return 0;
}

void fillDrivers(Driver arrayDrivers[]) {

    int i = 0;
    // Lewis Hamilton
    strcpy(arrayDrivers[i].name, "Lewis");
    strcpy(arrayDrivers[i].surname, "Hamilton");
    arrayDrivers[i].carNumber = 44;
    arrayDrivers[i].rookie = false;
    i  ;

}

The original codebase has all the drivers in the grid, i left only the first one to reduce the size. The problem is that this code gives me this error: Conflicting types for 'fillDrivers' at line 19. If in the struct i add the square brackets at Driver, i get this error: Array has incomplete element type 'Driver' (aka 'struct (unnamed struct at C:\Users\paual\Desktop\Uni\Programmazione\Homeworks\Homework_3nuovo\main.c:7:9) []'), this too at line 19.

What do i have to do?

CodePudding user response:

You need at first to declare the name Driver and only after that to use it in the function declaration

typedef struct{
    char name[20];
    char surname[20];
    int carNumber;
    bool rookie;
}Driver;

void fillDrivers(Driver[]);
  • Related