/* Note:Your choice is C IDE */
#include "stdio.h"
#include "malloc.h"
#include"stdlib.h"
#include"string.h"
#define LEN sizeof(struct bookadminister)
struct bookadminister
{
int number; /* 书号*/
char bname[10]; /* 书名*/
char wname[10]; /* 作者名*/
float price; /*价格*/
char date[10]; /*购买日期*/
struct bookadminister * next;
};
int n;
struct bookadminister *head;
int main()
{
struct bookadminister * creat();
void print(struct bookadminister *);
head=creat();
print(head);
return 0;
}
struct bookadminister *creat() /*建立新链表*/
{
struct bookadminister *p1,*p2;
n=0;
p1=p2=(struct bookadminister*)malloc(LEN);
printf("书号: ");scanf("%d",&p1->number);
printf("书名: ");scanf("%s",p1->bname);
printf("作者名: ");scanf("%s",p1->wname);
printf("价格: ");scanf("%f",&p1->price);
printf("购买日期:");scanf("%s",p1->date);
printf("\n");
head=NULL;
while(p1->number!=0) /*输入学号为“0”退出循环*/
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct bookadminister*)malloc(LEN);
printf("书号: ");scanf("%d",&p1->number);
printf("书名: ");scanf("%s",p1->bname);
printf("作者名: ");scanf("%s",p1->wname);
printf("价格: ");scanf("%f",&p1->price);
printf("购买日期:");scanf("%s",p1->date);
printf("\n");
}
p2->next=NULL;
return head;
}
void print(struct bookadminister * head) /*输出链表 */
{
struct bookadminister *p;
p=head;
if(head!=NULL)
printf("书号\t\t书名\t\t作者名\t\t价格\t\t购买日期\n ");
do
{
printf("%d\t\t%s\t\t %s\t\t%f\t%s\n",p->number,p->bname,p->wname,p->price,p->date);
p=p->next;
}while(head!=NULL);
}
#include "stdio.h"
#include "malloc.h"
#include"stdlib.h"
#include"string.h"
#define LEN sizeof(struct bookadminister)
struct bookadminister
{
int number; /* 书号*/
char bname[10]; /* 书名*/
char wname[10]; /* 作者名*/
float price; /*价格*/
char date[10]; /*购买日期*/
struct bookadminister * next;
};
int n;
struct bookadminister *head;
int main()
{
struct bookadminister * creat();
void print(struct bookadminister *);
head=creat();
print(head);
return 0;
}
struct bookadminister *creat() /*建立新链表*/
{
struct bookadminister *p1,*p2;
n=0;
p1=p2=(struct bookadminister*)malloc(LEN);
printf("书号: ");scanf("%d",&p1->number);
printf("书名: ");scanf("%s",p1->bname);
printf("作者名: ");scanf("%s",p1->wname);
printf("价格: ");scanf("%f",&p1->price);
printf("购买日期:");scanf("%s",p1->date);
printf("\n");
head=NULL;
while(p1->number!=0) /*输入学号为“0”退出循环*/
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct bookadminister*)malloc(LEN);
printf("书号: ");scanf("%d",&p1->number);
printf("书名: ");scanf("%s",p1->bname);
printf("作者名: ");scanf("%s",p1->wname);
printf("价格: ");scanf("%f",&p1->price);
printf("购买日期:");scanf("%s",p1->date);
printf("\n");
}
p2->next=NULL;
return head;
}
void print(struct bookadminister * head) /*输出链表 */
{
struct bookadminister *p;
p=head;
if(head!=NULL)
printf("书号\t\t书名\t\t作者名\t\t价格\t\t购买日期\n ");
do
{
printf("%d\t\t%s\t\t %s\t\t%f\t%s\n",p->number,p->bname,p->wname,p->price,p->date);
p=p->next;
}while(head!=NULL);
}