我试图了解我的代码是否正确。我需要声明一个指向结构的指针数组,创建一个新结构并分配值并打印它们。在我看来,我没有正确声明指针数组。我需要知道我做错了什么。谢谢我得到这个编译错误:错误:'people' undeclared (first use in this function) And I've try to insert struct data *list; 进入 main 但它不起作用
char *book[] = { "x", "y", "z",};
int number[] = { 1, 2, 3};
struct data = { char *bookname; int booknumber;};
function(char *x, int y)
{
static int count;
struct data *list[3];
//creating a new struct
list[count] = (struct data*) malloc( sizeof(struct data) );
//assigning arguments
list->bookname = x;
list->booknumber = y;
count++;
}
int main()
{
struct data *list[3];
int i;
for(i = 0; i < 3; i++)
{
function(book[i], number[i]);
printf("name: %c number: %d", list[i]->bookname, list[i]->booknumber);
}