一个练习的总结
练习的目标:写一个程序,利用结构体建立一个数据库存放图书数据。下面是代码:
#include<stdio.h>
#include<stdlib.h>
struct Book
{
char title[120];
char author[40];
float price;
unsigned int date;
char publisher[40];
};
void initialize(struct Book *book)
{
printf("the name of the book:\n");
scanf("%s", book->title);
printf("the name of the author:\n");
scanf("%s", book->author);
printf("price:\n");
scanf("%f", &book->price);
printf("date:\n");
scanf("%d", &book->date);
printf("publisher:\n");
scanf("%s", book->publisher);
}
void show(struct Book *book)
{
printf("This is the confirm of the informations:\n");
printf("Name:%s\n", book->title);
printf("Athor:%s\n", book->author);
printf("Price:%.2f\n", book->price);
printf("Date:%d\n", book->date);
printf("Publisher:%s\n", book->publisher);
printf("-----------------------------------------------\n");
}
int main(void)
{
struct Book *book[2];
for(int i =

本文是关于C语言结构体数组练习的总结,旨在建立一个图书数据库。主要问题包括:未为结构体指针分配内存、malloc使用不规范、编译器不支持中文输出、遗漏头文件#include <stdlib.h>、printf格式错误、for循环缺少int关键字初始化及漏写分号等。通过解决这些问题,加深了对C语言结构体和内存管理的理解。

1131

被折叠的 条评论
为什么被折叠?



