我無法理解如何初始化數組struct中的char數組。我寫了這樣的代碼:C初始化struct數組的char數組
typedef struct tomo
{
char titolo[100];
char autore[100];
int anno_pubblicazione;
float prezzo;
} t_libro;
main(){
t_libro biblio[2];
biblio[0] = {"Guida al C", "Fabrizio Ciacchi", 2003, 45.2};
biblio[1] = {"Harry Potter e la Pietra Filosofale", "J.K.Rowling", 2003, 12.5};
}
但是當我編譯時,它說我在'{'表達式是預期的。 我怎麼能解決它?這些字符陣列給我很多問題...
P.S. 我用盡也使用
biblio[0].titolo = "Guida al C";
,並以這種方式爲結構的其他領域,也以這種方式我有一個錯誤。
我總是用main()和它的作品。現在我嘗試你的例子,然後我說你是否工作:) – ProtoTyPus
它可能總是適合你的編譯器。但這是錯誤的。 –
在我的學院已經學會了我以這種方式進行...... = S 但是,您的解決方案的工作原理!非常感謝你! – ProtoTyPus