2
#include <stdio.h>
struct DVD {
char *movie_title;
int minutes;
float price;
};
void display_struct(struct DVD *ptr);
int
main()
{
struct DVD movies[10];
movies[0].movie_title = "I Am Legend"; //Don't want to do this
}
void
display_struct(struct DVD *ptr)
{
printf("%s\n%i\n%f\n", ptr->movie_title, ptr->minutes, ptr->price);
}
我想分配10部電影給我在一個單獨的語句結構的數組。這可能嗎?謝謝!
快速打字那裏! –
請注意,如果在您的編譯器中不可用,「dot-field-name =」是C. 的一個相對較新的添加,您可以使用不帶字段名稱的值。 – abelenky
如果您按順序初始化,您甚至不需要指示符(並且它在C99之前工作)。 –