I am trying to initialize an array of structs using a function but when in the middle of the initializing the array of structs, it shows "segmentation fault (core dumped)":
#include <stdio.h>
enum carType
{
sedan,
suv,
hatchback,
muv
};
typedef enum carType carType;
struct Car
{
int modelNo;
char *modelName;
float price;
carType type;
};
typedef struct Car Car;
void init(Car* c, int s)
{
for (int i = 0; i < s; i++)
{
scanf("%d", &(c[i].modelNo));
scanf("%s", c[i].modelName);
scanf("%f", &(c[i].price));
scanf("%d", &(c[i].type));
}
}
int main()
{
Car arr[2];
printf("Enter values for members of array of Cars : \n");
init(arr, 2);
return 0;
}