如何打印动态数组书籍 * arr 以及我是否必须添加更多
内容 如何打印动态数组书籍 * arr 如何打印动态数组书籍 * arr
typedef struct Book
{
char name[32];
char genre[32];
char author[32];
int numOfPages;
int price;
}books;
struct Library
{
char name[32];
books* arr;
int numOfBooks;
};
int main()
{
struct Book book1;
strcpy(book1.name,"Learn C.");
strcpy(book1.genre,"Fantastic");
strcpy(book1.author,"Dont know who");
kniga1.numOfPages=666;
kniga1.price=100;
books* arr=(books*)malloc(sizeof(books));
struct Library library1;
strcpy(library1.name,"Biblioteka1");
library1.numOfBooks=1;
关于您的问题:*如何打印动态数组书籍 * ar*...
假设您已经创建了这样的数组(发布的代码尚未创建。
for( size_t i = 0; i < library1.numOfBooks; i++ )
{
printf( "%s ", library1.arr[i]->name );
printf( "%s ", library1.arr[i]->genre );
printf( "%s ", library1.arr[i]->author );
printf( "%d ", library1.arr[i]->numOfPages );
printf( "%dn", library1.arr[i]->price );
}