求助帖,谁能告诉我运行过程中晚上会崩溃呀,求大版主,求神仙!!
程序代码:
#include <stdio.h> #include <string.h> #include <stdbool.h> #include "tree.h" enum allchoices {addone,deleteone,itemcount,search,showall,cleanall}; const char * choices[]={"addone","deleteone","itemcount","search","showall","cleanall"}; #define LEN 15 void menu(void); void AddOne (Tree *ptree); void DeleteOne(Tree *ptree); unsigned int ItemCount(const Tree *ptree); void FindOne(const Tree *ptree); void ShowAll(const Tree *ptree); void CleanAll(Tree *ptree); void PrintItem(Item item); int main(void) { Tree classmates; char yourchoice[LEN]; enum allchoices choice; bool the_order_iseffective=false; menu(); while(strcmp(gets(yourchoice),"quit")!=0&&yourchoice[0]!='\0') { for(choice=addone;choice<=cleanall;choice++) { if(strcmp(yourchoice,choices[choice])==0) { the_order_iseffective=true; break; } } if(the_order_iseffective) switch (choice) { case (addone): AddOne(&classmates); break; case (deleteone):DeleteOne(&classmates); break; case(itemcount):ItemCount(&classmates); break; case(search):FindOne(&classmates); break; case(showall):ShowAll(&classmates); break; case(cleanall):CleanAll(&classmates); break; } else printf("i don\'t know what the order mean!\n"); the_order_iseffective=false; puts("next order\n"); menu(); } puts("good job\n"); return 0; } void menu(void) { puts("please chioce what do you want to to?\n"); puts("enter \"addone\" to add a classmate.\n"); puts("enter \"deleteone\" to delete a classmate\n"); puts("enter \"itemcount\" to konw the number of your classmatas\n"); puts("enter \"search\" to find your classmate\n"); puts("enter\"showall\"to printf all of your classmates.\n"); puts("enter \"cleanall\"to chean all items. \n"); puts("enter \"quit\" to quit\n"); return 0; } void AddOne (Tree *ptree) { Item temp; if(TreeIsFull(ptree)) puts("no room to accept a new one!\n"); else { puts("please enter your classmate\'s name:\n"); gets(temp.name); puts("please enter sex of your classmate:\n"); gets(temp.sex); puts("please enter age of your classmate:\n"); scanf("%d",&temp.age); AddItem(&temp,ptree); } printf("just like this.\n"); } void DeleteOne(Tree *ptree) { Item temp; if(TreeIsEmpty(ptree)) { puts("no members to put out!\n"); return; } puts("please enter name of classmate you want to delete:\n"); gets(temp.name); if(DeleteItem(&temp,ptree)) printf("sccessfully\n"); else puts("is not a members\n"); printf("just like\n"); } unsigned int ItemCount(const Tree *ptree) { unsigned int count; count=TreeItemCount(ptree); printf("just like2\n"); return count; } void FindOne(const Tree *ptree) { Item temp; if(TreeIsEmpty(ptree)) { puts("no information in the tree!"); return; } puts("please enter name of classmate you want to find:\n"); gets(temp.name); if(InTree(&temp,ptree)) puts("is a member in the class!"); else puts("is not a member"); printf("just like 3\n"); } void ShowAll(const Tree *ptree) { if(TreeIsEmpty(ptree)) { puts("no information in the tree!"); return; } else Traverse(ptree,PrintItem); printf("just like 4\n"); } void CleanAll(Tree *ptree) { DeleteAll(ptree); printf("just clean all\n"); } void PrintItem(Item item) { printf("name:%s,\tsex:%s,\tage:%d",item.name,item.sex,item.age); }