| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:链表数据读取问题
只看楼主 加入收藏
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
结帖率:81.82%
收藏
已结贴  问题点数:20 回复次数:5 
链表数据读取问题
程序代码:
//头文件
#ifndef _HEAD_
#define _HEAD_
#define NSIZE 45
struct film{
    char title[NSIZE];        //用于存放电影名 
    int  rating;            //评分 
};
typedef  struct film Film;
struct node{
    Film item;
    struct node *next;         //指向下一节点的指针 
};
typedef  struct node NODE;
typedef  NODE*  LIST;
void initialization (LIST *pfile);      //初始化链表 
bool listisfull(void);                    //没什么用 
void additem(LIST* pfile,Film list);    //向链表尾部添加数据 
void cleanlist(LIST *pfile);            //释放链表 
void copystr(Film film,LIST pfile);        //将数据存入节点 
int showlist(LIST pfile);    //显示数据 
#endif
//主函数
#include<stdio.h>
#include<stdlib.h>
#include"head.h"
int main(void)
{
    Film list;
    LIST movies;
    initialization (&movies);  //初始化 
    printf("please enter the title of movie\n");
    while((gets(list.title)!=0)&&(list.title[0]!='\0'))
    {
        puts("enter your grade(0~10)");
        scanf("%d",&list.rating);
        while(getchar()!='\n')
            continue;
        additem(&movies,list);
        listisfull();
        puts("enter the title of the next film");
    }
    showlist(movies);
    cleanlist(&movies);
    puts("bye~");
    return 0;
}
void initialization (LIST *pfile)
{
    *pfile=NULL;
}
bool listisfull(void)
{
    LIST p;
    p=(LIST)malloc(sizeof(node));
    if(p==NULL)
    {
        fprintf(stderr,"the list is already full\n");
        exit(1);
    }
    return false; 
}
void additem(LIST* pfile,Film list)
{
    if(*pfile==NULL)
    {
        *pfile=(LIST)malloc(sizeof(node));
        copystr(list,*pfile);
        (*pfile)->next=NULL;
    }
    else
    {
        LIST p;
        p=*pfile;
        while(p!=NULL)
            p=p->next;
        copystr(list,p);
        p->next=NULL;
    }
}
void cleanlist(LIST *pfile)
{
    LIST p;
    while(*pfile!=NULL)
    {
        p=(*pfile)->next;
        free(*pfile);
        *pfile=p;
    } 
    puts("clean up!");
}
int showlist(LIST pfile)
{
    int count=0;
    while(pfile!=NULL)
    {
        count++;
        printf("%2d:%45s  %2d\n",count,pfile->item->title,pfile->item->rating);
//问题出在printf这里,编译器一直报错。具体报错在最后
        pfile=pfile->next;
    }
    return count;
}
void copystr(Film film,LIST pfile)
{
    pfile->item=film;
}

    [Error] base operand of '->' has non-pointer type 'Film {aka film}'
        [Error] base operand of '->' has non-pointer type 'Film {aka film}'
请问是哪里不对,编译器的报错看不明白
搜索更多相关主题的帖子: color 
2015-10-01 09:39
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:7 
showlist(LIST pfile)

showlist(LIST *pfile)

一片落叶掉进了回忆的流年。
2015-10-01 09:59
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 2楼 诸葛欧阳
能不能稍微说详细点
之前我用的是show(LIST *pfile)但感觉没必要,只是读数据,不对链表进行操作啊?
2015-10-01 10:15
cprimerplus
Rank: 2
等 级:禁止发言
帖 子:8
专家分:23
注 册:2015-10-1
收藏
得分:7 
提示: 作者被禁止或删除 内容自动屏蔽
2015-10-01 11:29
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
回复 4楼 cprimerplus
跑这里打广告你也是够了,吐槽加自顶
2015-10-01 14:25
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
收藏
得分:0 
实在想不通哪里的问题了~~
2015-10-01 20:12
快速回复:链表数据读取问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016544 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved