为什么我会犯这个错误?:incompatible types when assigning to type 'struct LocationArray *[(sizetype)(numberOfLoc)]' from type 'struct LocationArray *'|
在main()
中的下一行?
myArray = (LocationArray*)malloc(numberOfLoc*sizeof(LocationArray));
Code:
//structure Location
typedef struct Location{
char locName[35];
char locDesc[85];
float latitude;
float longitude;
} LocationArray;
int main()
{
printf("How many locations would you like to be inside the array?\n");
int numberOfLoc = 0; //variable for storing the size of the LocationArray
scanf("%d", &numberOfLoc); //gets the user input and stores in numerOfLoc
LocationArray *myArray[numberOfLoc]; //declares a LocationArray with the size of numberOfLoc
myArray = (LocationArray*)malloc(numberOfLoc*sizeof(LocationArray));
//Print the menu
printMenu(&myArray);
//Free the pointer
free(myArray);
return 0;
}
最佳答案
LocationArray *myArray[numberOfLoc];
应该是LocationArray *myArray;
。