試圖讓我周圍的舊的C語言頭。目前在結構和收到此錯誤:C:變量初始化,但不完全類型
"variable 'item1' has initializer but incomplete type"
這裏是我的代碼:
typedef struct
{
int id;
char name[20];
float rate;
int quantity;
} item;
void structsTest(void);
int main()
{
structsTest();
system("PAUSE");
return 0;
}
void structsTest(void)
{
struct item item1 = { 1, "Item 1", 345.99, 3 };
struct item item2 = { 2, "Item 2", 35.99, 12 };
struct item item3 = { 3, "Item 3", 5.99, 7 };
float total = (item1.quantity * item1.rate) + (item2.quantity * item2.rate) + (item3.quantity * item3.rate);
printf("%f", total);
}
我猜也許是結構確定指標是在錯誤的位置,所以我把它移動到文件並重新編譯的頂部,但我仍然遇到同樣的錯誤。我的錯誤在哪裏?