#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
#define SIZE sizeof(bookinfo)
typedef struct bookinfo{
char title[20];
char author[40];
int acquisition_year;
long serial_number;
char family[2];
int copys;
struct bookinfo* next;
}bookinfo;
#include "stdio.h"
void main(){
int flag,i;
char command;
bookinfo* list=NULL,*head=NULL;
Command: printf("registerd a new book enter 1\n");
printf("list all registered books enter 2\n");
printf("exit enter 3\n");
scanf("%d",&flag);
switch(flag){
case 1:{
printf(">do you want to register a book?(y/n)");getchar();
scanf("%c",&command);
if(command=='y'){
head=list=(bookinfo*)malloc(SIZE);
list->next=NULL;
printf(">please give the initial serial number?");
scanf("%ld",&list->serial_number);
printf(">give the title?");
scanf("%s",list->title);
printf("give the author's name?");
scanf("%s",list->author);
printf(">give the acquisition year?");
scanf("%d",&list->acquisition_year);
printf(">how many copys?");
scanf("%d",&list->copys);
printf("give the family(NS,HS,MC,F,PH,A)?");
scanf("%s",list->family);
system("cls");
}
else goto Command;
printf(">do you want to register another book?(y/n)");
getchar();
scanf("%c",&command);
while(command=='y'){
list->next=(bookinfo*)malloc(SIZE);
list=list->next;
list->next=NULL;
printf(">please give the initial serial number?");
scanf("%ld",&list->serial_number);
printf(">give the title?");
scanf("%s",list->title);
printf("give the author's name?");
scanf("%s",list->author);
printf(">give the acquisition year?");
scanf("%d",&list->acquisition_year);
printf(">how many copys?");
scanf("%d",&list->copys);
printf("give the family(NS,HS,MC,F,PH,A)?");
scanf("%s",list->family);
system("cls");
printf(">do you want to register another book?(y/n)\n");
getchar();
scanf("%c",&command);
}
list=head;
system("cls");
break;
}
case 2:{
if(!list){system("cls");printf("no record,please create one\n");}
else{ system("cls");
while(list){
printf("title auth_name acq_year regi.codes\n");
for(i=0;i
printf("%s ",list->title);
printf("%s ",list->author);
printf("%d ",list->acquisition_year);
printf("%s ",list->family);
printf("%d ",list->acquisition_year);
printf("%ld ",list->serial_number);
printf("%c\n",65+i);
}
list=list->next ;
}
}
list=head;
printf("return to the menu press 1 \n");
printf("exit press 0\n");
getchar();
scanf("%d",&flag);
if(flag==1) system("cls");
else goto exit;
break;
}
exit:case 3:{
while(list){
list=head->next;
free(head);
head=list;
}
return;
}
default: { printf("con't find this command\n");goto Command;}
}
goto Command;
}
昨天那个是在VC上运行的,今天抽空改了下,可以在TC上运行的.具体效果见:
http://mcs.szu.edu.cn/attach/DD848CBB-50E7-4F34-A2A3-B12F41960164