0
這裏是我的代碼:結構問題:初始化將指針整數,未作鑄
#include <stdio.h>
#include <string.h>
#define Length 20
struct Capacitor
{
char Model[Length];
int Capacitance;
float Voltage;
float Cost;
};
void displayCapacitorInfo(struct Capacitor List[])
{
int i;
for (i = 0; i < 4; i++)
{
printf("Capacitor %s:\n\n", List[i].Model);
printf(" *Capacitance: %d uF\n", List[i].Capacitance);
printf(" *Voltage: %f V\n", List[i].Voltage);
printf(" *Cost: $%f\n", List[i].Cost);
printf("\n");
}
}
int main()
{
float Cost, Voltage;
int Capacitance;
char Model[Length];
struct Capacitor a;
struct Capacitor b;
struct Capacitor c;
struct Capacitor d;
strcpy(a.Model, "11-123U");
a.Capacitance = 100;
a.Voltage = 25;
a.Cost = 6.00;
strcpy(b.Model, "65T91a");
b.Capacitance = 22000;
b.Voltage = 20;
b.Cost = 25.00;
printf("Model number of 1st capacitor: %s\n", a.Model);
printf("Voltage of 2nd capacitor: %f V\n", b.Voltage);
printf("\n");
printf("Model number of 3rd capacitor:");
scanf("%s", &c.Model);
printf("\n");
printf("Capacitance of 3rd capacitor:");
scanf("%d", &c.Capacitance);
printf("\n");
printf("Voltage of 3rd capacitor:");
scanf("%f", &c.Voltage);
printf("\n");
printf("Cost of 3rd capacitor:");
scanf("%f", &c.Cost);
printf("\n\n");
printf("Model number of 4th capacitor:");
scanf("%s", &d.Model);
printf("\n");
printf("Capacitance of 4th capacitor:");
scanf("%d", &d.Capacitance);
printf("\n");
printf("Voltage of 4th capacitor:");
scanf("%f", &d.Voltage);
printf("\n");
printf("Cost of 4th capacitor:");
scanf("%f", &d.Cost);
printf("\n\n");
struct Capacitor List[] = { {a.Model, a.Capacitance, a.Voltage, a.Cost}, {b.Model, b.Capacitance, b.Voltage, b.Cost}, {c.Model, c.Capacitance, c.Voltage, c.Cost}, {d.Model, d.Capacitance, d.Voltage, d.Cost} };
displayCapacitorInfo(List);
return 0;
}
輸出:
我有我的數組列表的麻煩[],特別是當我嘗試輸入電容器的型號時。結構體a,b,c和d的Model元素在輸入到數組List []中時會產生一個「初始化從指針沒有轉換的整數」警告。
我能做些什麼來解決這個問題?
感謝您的幫助。
更改爲:'結構電容列表[] = {a,b,c,d};' –
@PaulGriffiths謝謝,這工作。 –
請複製並粘貼警告(和結果)作爲我們的文本,以便搜索引擎不必解析您的圖像文件,以便爲後代編制索引此問題。請在你的餘生中記住這一點,因爲將文字放入圖像中的人(如你)正在迅速爲互聯網的死亡做出貢獻。 – Sebivor