弱弱的问下!
编程器警告发出2条警告! 传递参数1的不相容的指针类型的列表预期的结构节点* const *’但参数的类型是列表
是什么意思!
#ifndef LIST_H_ #define LIST_H_ #include<stdbool.h> #define TSIZE 45 struct film { char title[TSIZE]; int rating; }; typedef struct film Item; typed ef struct node { Item item; struct node *next; }Node; typedef Node *List; void InitializeList(List *plist); bool ListIsEmpty(const List *plist); bool ListIsFull(const List *plist); unsigned int ListItemCount(const List *plist); bool AddItem(Item item,List *plist); void Traverse(const List *plist,void(*pfun)(Item item)); void EmptyTheList(List *plist); #endif // LIST_H_INCLUDED
#include<stdio.h> #include<stdlib.h> #include "list.h" void showmovies(Item item); int main(void) { List movies; Item temp; InitializeList(&movies); if(ListIsFull(movies)) { fprintf(stderr,"没有可用内存!Bye!\n"); exit(1); } puts("进入第一个电影标题:"); while(gets(temp.title)!=NULL&&temp.title[0]!='\0') { puts("输入你的评价<0-10>:"); scanf("%d",&temp.rating); while(getchar()!='\n') continue; if(AddItem(temp,&movies)==false) { fprintf(stderr,"问题分配内存\n"); break; } if(ListIsFull(movies)) { puts("列表已满."); break; } puts("进入下一个电影标题(空行停止):"); } if(ListIsEmpty(movies)) printf("没有数据输入."); else { printf("这是电影列表: \n"); Traverse(movies,showmovies); } printf("你进入 %d 电影.\n",ListItemCount(movies)); EmptyTheList(&movies); printf("Bye!\n"); return 0; } void showmovies(Item item) { printf("Movie: %s Rating %d\n",item.title,item.rating); }
#include <stdio.h> #include <stdlib.h> #include "list.h" static void CopyToNode(Item item, Node * pnode); void InitializeList(List *plist) { *plist=NULL; } bool ListIsEmpty(const List *plist) { if(*plist==NULL) return true; else return false; } bool ListIsFull(const List * plist) { Node *pt; bool full; pt=(Node *)malloc(sizeof(Node)); if(pt==NULL) full=true; else full=false; free(pt); return full; } unsigned int ListItemCount(const List *plist) { unsigned int count=0; Node *pnode=*plist; while(pnode!=NULL) { ++count; pnode=pnode->next; } return count; } bool AddItem(Item item,List *plist) { Node *pnew; Node *scan=*plist; pnew=(Node *)malloc(sizeof(Node)); if(pnew==NULL) return false; CopyToNode(item,pnew); pnew->next=NULL; if(scan==NULL) *plist=pnew; else { while(scan->next!=NULL) scan=scan->next; scan->next=pnew; } return true; } void Traverse(const List * plist,void(*pfun)(Item item)) { Node *pnode=*plist; while(pnode!=NULL) { (*pfun)(pnode->item); pnode=pnode->next; } } void EmptyTheList(List *plist) { Node *psave; while(*plist!=NULL) { psave=(*plist)->next; free(*plist); *plist=psave; } } static void CopyToNode(Item item,Node *pnode) { pnode->item=item; }