分配给类型`'时不兼容的类型;结构位置数组*[(sizetype)(numberOfLoc)]';`从类型';结构位置数组*'|
为什么我会犯这个错误分配给类型`'时不兼容的类型;结构位置数组*[(sizetype)(numberOfLoc)]';`从类型';结构位置数组*'|,c,struct,C,Struct,为什么我会犯这个错误 从类型“struct LocationArray*”分配给类型“struct LocationArray*[(sizetype)(numberOfLoc)]”时不兼容的类型 在main() 代码: //structure Location typedef struct Location{ char locName[35]; char locDesc[85]; float latitude; float longitude; } Locatio
从类型“struct LocationArray*”分配给类型“struct LocationArray*[(sizetype)(numberOfLoc)]”时不兼容的类型
在main()
代码:
//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代码>位置数组*myArray[numberOfLoc]代码>应该是LocationArray*myArray代码>哦!谢谢@基思莫。还有一个问题:我如何检查结构数组的大小是否已满?我不明白你所说的“满”或“不”是什么意思。你能举个例子吗?我想检查myArray
的大小是否已满,即数组是否已满。我怎么能做到呢?语言中没有内置的东西,你需要自己来做。哦!谢谢@基思莫。还有一个问题:我如何检查结构数组的大小是否已满?我不明白你所说的“满”或“不”是什么意思。你能举个例子吗?我想检查myArray
的大小是否已满,即数组是否已满。我该怎么做呢?语言中没有内置的东西,你需要自己做。
//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;
}