C 语言代码:展示图书馆书籍信息
这段代码定义了一个函数 'show_books',用于展示图书馆中的书籍信息。该函数接受一个指向 Book 结构体的指针作为参数,该指针指向链表的头节点。函数首先输出表头,然后遍历整个链表,逐个输出每本书的编号、名称、作者和借阅状态。如果当前书籍的状态为 0,则输出'未借出';否则输出'已借出'。最后,函数返回。
void show_books(Book *head) {
printf('书籍编号 书籍名称 作者 借阅状态
');
Book *current = head;
while (current != NULL) {
printf('%d %s %s %s
', current->id, current->name, current->author, current->status == 0 ? '未借出' : '已借出');
current = current->next;
}
}
原文地址: https://www.cveoy.top/t/topic/mpWh 著作权归作者所有。请勿转载和采集!