图书管理系统(C语言实现)(全部代码)!
typedefstructbook{
char*name;
intid;
intcount;
intstatus;
structbook*next;
Book*head=NULL;
intnbook=0;
intmain(){
welcome();
return0;
}voidwelcome(){
while(1){
switch(land()){
if(usrmanager()){
continue;
}else{
break;
}
if(usrstudent()){
exit(0);
default:
}charland(){
charc,flag;
inti;
;
if(i==1){
returnflag;
}elseif(i==0){
}voiderror(char*s){
}chardostudent(){
}intusrstudent(){
switch(dostudent()){
borrowbook();
returnbook();
viewbook();
return1;
}intborrowbook(){
system(CLEAR);
charsname[MAXNAME];
getchar();
Book*bp;
char*namep=NULL;
if((bp=lookup(namep=strdup(sname),0))==NULL){
fflush(stdin);
return-1;
printbook(bp);
if(!bp->status){
if(!bp->count){
bp->status=UNAVAILABLE;
returnbp->id;
}intreturnbook(){
char*namep;
bp->count++:(bp->status=AVAILABLE);
}chardomanager(){
}intusrmanager(){
switch(domanager()){
addbook();
modbook();
delbook();
}intviewbook(){
system(CLEAR);///////////////////////////////////////////Book*bp;
for(bp=head;bp!=NULL;bp=bp->next){
if(nbook){
returnnbook;
}voidprintbook(Book*bp){
}intaddbook(){
system(CLEAR);///////////////////////////////////////////charsname[MAXNAME];
intid,count;
id=0;
count=0;
namep=NULL;
if(!(id>0&&id<1000)){
if(!(count>0&&count<50)){
if((bp=lookup(namep=strdup(sname),id))==NULL){
bp=(Book*)malloc(sizeof(Book));
if(bp==NULL||(bp->name=namep)==NULL){
bp->id=id;
bp->count=count;
bp->status=AVAILABLE;
++nbook;
bp->next=head;
head=bp;
returnid;
Book*lookup(char*s,intid){
if(id==bp->id||strcmp(s,bp->name)==0){
returnbp;
returnNULL;
}intmodbook(){//修改除id之外的信息因为要修改id直接删掉后重新添加会更好system(CLEAR);///////////////////////////////////////////Book*bp=NULL;
intid=0;
if(!(i==1||i==2||i==3||i==0)){
switch(i){
case1:
charnewname[MAXNAME],*namep;
if((lookup(namep=strdup(newname),0))!=NULL){
if((bp->name=namep)!=NULL){
case2:
intbnum;
if(!(bnum>0||bnum<1000)){
bp->count=bnum;
case3:
charc;
status=bp->status;
status==AVAILABLEbp->status=UNAVAILABLE:(bp->status=AVAILABLE);
case0:
}intdelbook(){
system(CLEAR);///////////////////////////////////////////Book*bp,*fbp;
for(fbp=bp=head;bp!=NULL;fbp=bp,bp=bp->next){
if(bp->id==id){
if(bp!=NULL){
charYN;
bp==headhead=bp->next:(fbp->next=bp->next);
free(bp->name);//2018-05-26修改:添加释放name这块内存//bp内存的只是指向name的指针