标题:C primer Plus上的电影列表题,用VC++6.0编译,弹出调试窗口,怎么办呢?
只看楼主
henrycatcat
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-8
结帖率:100%
已结贴  问题点数:10 回复次数:2 
C primer Plus上的电影列表题,用VC++6.0编译,弹出调试窗口,怎么办呢?
list.h文件:
#ifndef LIST_H_
#define LIST_H_
#define bool int
#define true 1
#define false 0
#define TSIZE 45
typedef struct film{
    char title[TSIZE];
    int rating;
}Item;
typedef 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.c文件:
#include<stdio.h>
#include<stdlib.h>
#include"list.h"
static void CopyToNode(Item item,List *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)
        *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 Copytopnode(Item item,Node *pnode)
{
    pnode->item=item;
}

film3文件:
#include<stdio.h>
#include<stdlib.h>
#include "List.h"
void showmovies(Item item);
int main()
{
    List movies;
    Item temp;
    Initializelist(&movies);
    if(Listisfull(movies))
    {
        fprintf(stderr,"No memory available! Bye!\n");
        exit(1);
    }
    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')
            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("You enter %d movies.\n",Listitemcount(&movies));
    Emptythelist(&movies);
    printf("Byb!\n");
    return 0;
}
void showmovies(Item item)
{
    printf("movie: %s rating:%d\n",item.title,item.rating);
}
搜索更多相关主题的帖子: void 怎么办 rating title 
2013-05-14 20:56
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
得分:10 
你用书本自带的代码编译后能运行吗?

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-05-14 22:00
henrycatcat
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-8
得分:0 
回复 2楼 pauljames
用VC++6.0和codeblocks都过不去
2013-05-15 14:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-407090-1-1.html




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

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