int main(void) { List movies; Item temp; /* initialize */ InitializeList(&movies); if (ListIsFull(&movies)) { fprintf(stderr,"No memory available! Bye!\n"); exit(1); } /* gather and store */ puts("Enter first movie title:"); while (get(temp.title, TSIZE) != NULL && temp.title[0] != '\0') { puts("Enter your rating <0-10>:"); scanf("%d", &temp.rating); while(getchar() != '\n') continue; if (AddItem(temp, &movies)==false) { fprintf(stderr,"Problem allocating memory\n"); break; } if (ListIsFull(&movies)) { puts("The list is now full."); break; } puts("Enter next movie title (empty line to stop):"); } /* display */ if (ListIsEmpty(&movies)) printf("No data entered. "); else { printf ("Here is the movie list:\n"); Traverse(&movies, showmovies); } printf("You entered %d movies.\n", ListItemCount(&movies)); /* clean up */ EmptyTheList(&movies); printf("Bye!\n"); return 0; }
int main(void) { List movies; Item temp; /* Initialize */ InitializeList(&movies); if(ListIsFull(&movies)) { fprintf(stderr,"No memory avaliable! Bye!\n"); exit(1); } /* collecte and storage data */ puts("Enter first movie title :"); while(gets(temp.title) != NULL && temp.title[0] != '\0') { puts("Enter your rating <0-10> : "); scanf("%d",&temp.rating); while(getchar() != '\n'); if(AddItem(temp,&movies) == false) { fprintf(stderr,"Problem allocating memory\n"); break; } if(ListIsFull(&movies)) { puts("The list id full."); break; } puts("Enter next movie title (empty line to quit):"); } /* Display List */ if(ListIsEmpty(&movies)) printf("No data entred."); else { printf("Here is the movie list :\n"); Traverse(&movies,showmovies); } printf("Your entered %d movies.\n",ListItemCount(&movies)); /* clean list */ EmptyTheList(&movies); printf("Bye!\n"); return 0; }
//显示列表内容 void show(List * plist) { if (ListIsEmpty(plist)) { puts("No data!"); } else { printf("Here is the car's information:\n"); Traverse(plist, showList); } printf("There is %d car in your list.\n", ListItemCount(plist)); }
int main(int argc, char ** argv) { List movies; Item temp; /* 初始化 */ InitializeList(&movies); if (ListIsFull(&movies)){ fprintf(stderr, "No memory available! Bye!\n"); exit(EXIT_FAILURE); } /* 收集并存储 */ fputs("Enter first movie title: \n", stdout); while (fgets(temp.title, TSIZE, stdin) != NULL && temp.title[0] != '\n'){ reject_ch(temp.title, '\n'); fputs("Enter your rating<0-10>: \n", stdout); scanf_s("%d", &temp.rating); while (getchar() != '\n'){ continue; } if (false == AddItem(&temp, &movies)){ fprintf(stderr, "Problem allocating memory\n"); exit(EXIT_FAILURE); } if (ListIsFull(&movies)){ fputs("The list is now full.\n", stdout); break; } fputs("Enter next movie title(empty line to stop): \n", stdout); } /* 显示 */ if (ListIsEmpty(&movies)) printf("No data entered."); else{ printf("Here is the movie list: \n"); Traverse(&movies, showMovies); } printf("You entered %d movies.\n", ListItemCount(&movies)); /* 清除 */ EmptyTheList(&movies); printf("Bye!\n"); _CrtDumpMemoryLeaks(); return EXIT_SUCCESS; }
int main(void) { List list; InitializeList(&list); // test Initialize if(ListIsEmpty(&list)) //test ListIsEmpty printf("the list is empty\n"); else printf("the list is not empty\n"); // unsigned int counter=0; // counter=ListItemCount(&list); Node* pnode; pnode=(Node*)malloc(sizeof(Node)); Item *pitem; pitem=(Item*)malloc(sizeof(Item)); pitem->ID=001; strcpy(pitem->content, "hello list"); pitem->value=1; pnode->item=*pitem; list=pnode; list=AddNew(list); //test AddNew unsigned int counter=0; counter=ListItemCount(&list); printf("there are %u items in the list\n", counter); // void (*pfun)(Item item)=showitem; Traverse(&list,showitem); //test Traverse // EmptyTheList(&list);d if(ListIsEmpty(&list)) printf("list is empty!\n"); else printf("list is not empty!\n"); EmptyTheList(&list); return 0; }
int main() { List movies; Item temp; InitializeList(&movies); if(ListIsFull(&movies)) { fprintf(stderr,"no memory available!\nBye!\n"); exit(1); } puts("enter first movie title:"); while(gets(temp.title) != NULL && temp.title[0] != '\0') { puts("enter your rating:"); scanf("%d",&temp.rating); while(getchar() != '\n') continue; if(AddItem(temp,&movies) == false) { fprintf(stderr,"Problem allocating memory\n"); break; } if(ListIsFull(&movies)) { puts("the list is full"); break; } puts("enter next movie title:"); } if(ListIsEmpty(&movies)) { printf("no data entered."); } else { printf("here is the movie list:\n"); Traverse(&movies,ShowMovies); } printf("you entered %d movies.\n",ListItemCount(&movies)); EmptyTheList(&movies); printf("Bye!\n"); return 0; }
int main(void) { List movies; Item temp; /*初始化*/ InitializeList(&movies); if(ListIsFull(&movies)) { fprintf(stderr,"no memory available!\n"); exit(1); } /*收集并存储*/ puts("enter first movie title"); while(fgets(temp.title,TSIZE,stdin) != NULL && temp.title[0] != '\n') { puts("enter your rating <0-10>:"); scanf("%d",&temp.rating); while(getchar() != '\n') continue; if(AddItem(temp,&movies) == false) { fprintf(stderr,"problem allocating memory\n"); break; } if(ListIsFull(&movies)) { puts("the list is now full."); break; } puts("enter next movie title(empty line to stop)"); } if( ListIsEmpty(&movies) ) printf("no data entered."); else { printf("here is the movie list:\n"); Traverse(&movies,showmovies); } printf("your entered %d movies.\n",ListItemCount(&movies) ); /*清除*/ EmptyTheList(&movies); printf("bye!\n"); return 0; }