I cannot manage to solve the error, even though I've used these types of structures in other project in the same manner and it worked.
Meanwhile I'm not getting an errors in the declaration or initialisation of my structures.
The idea is to read information about a bunch of cars from a binary file. It tells me that "struct Car" is an incomplete type and not allowed. Here's the code I've made so far:
car.c
#include <stdio.h>
#include <string.h>
#include "car.h"
#define MAX_NUMBER_OF_CARS 10
struct Car importedCars[MAX_NUMBER_OF_CARS];
struct Config importedConfigs[MAX_NUMBER_OF_CARS];
int main( int argc, char* argv[]){
FILE *fp;
fp = fopen("cars.bin","rb");
if(fp != NULL)
{
fread(importedCars,sizeof(struct Car),MAX_NUMBER_OF_CARS,fp);
printf("1. Binary File read, structures of cars created.\n\n");
for(int i = 0; i < MAX_NUMBER_OF_CARS; i++)
{
printf("%s\t%s\t%s\t%d\t%f\t%f\t%f\t%d\n", importedCars[i].make, importedCars[i].model, importedCars[i].configuration.fuelType, importedCars[i].power, importedCars[i].torque, importedCars[i].fuelConsumption, importedCars[i].co2PerKm, importedCars[i].price);
}
}
else
{
printf("cannot read file.\n");
}
fclose(fp);
return 0;
}
car.h
#ifndef _CAR_H_
#define _CAR_H_
#define fuelLength 10
#define gearLength 10
#define conditionLength 10
#define makeLength 30
#define modelLength 30
typedef struct {
char fuelType[fuelLength];
char gearType[gearLength];
int numGears;
char condition[conditionLength];
} Config;
typedef struct {
char make[makeLength];
char model[modelLength];
Config configuration;
short power;
float torque;
float fuelConsumption;
float co2PerKm;
int price;
} Car;