I am still learning C and I am doing an exercise where I have to program a car database. In the main function I declared an array of 100 pointers to 'carinfo_t' structures. In the function '*createcarinfo' a new carinfo_t instance should be created. But I get the problem that the 'brandOfCar' variable is undeclared. I do not really understand why I am getting this message because the compiler should know that this variable is part of the structure, right? The structure is declared as a datatype in the program and a pointer to the struct is initialized in the beginning of this function.
I am sorry if this question has already been asked somewhere. Any help is very much appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <limits.h>
struct carinfo_t
{
char *brandOfCar;
char *modelOfCar;
int yearCarWasBuilt;
float valueOfCar;
};
struct carinfo_t *createCarinfo(char *brand, char *model, int year, float
value)
{
struct carinfo_t *newCarInfo=(struct carinfo_t*) malloc(sizeof(struct
carinfo_t));
newCarInfo->brandOfCar=(char*)malloc(sizeof(char)*
(strlen(brandOfCar)+1));
//Message: error: 'brandOfCar' undeclared (first use in this function)
//function not finished
}
int main()
{
struct carinfo_t *carbase[100]={};
return 0;
}