| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 708 人关注过本帖
标题:一道结构体链表问题
只看楼主 加入收藏
雪天
Rank: 1
等 级:新手上路
帖 子:18
专家分:5
注 册:2009-7-23
结帖率:40%
收藏
已结贴  问题点数:100 回复次数:5 
一道结构体链表问题
原题:
图书馆的图书检索卡记载的内容包括:书名、作者姓名、出版日期、页数、定价等内容。根据上述内容定义一个结构体类型,并按照作者姓名进行查找,按照出版日期顺序从远到近打印出该作者的所有著作。
程序错误:
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
1>C:\Users\ligang\Desktop\C++专用\6-3\Debug\6-3.exe : fatal error LNK1120: 1 个无法解析的外部命令

我的程序:
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#define NULL 0
#define LEN sizeof(struct bookcard)
struct date
{
    int year;
    int month;
    int day;
};
struct bookcard
{
    char bookname[50];
    char author[20];
    struct date publish;
    int page;
    float price;
    struct bookcard *next;
};
struct bookcard0
{
    char bookname[50];
    char author[20];
    struct date publish;
    int page;
    float price;
};
struct bookcard *create()
{
    int n;
    struct bookcard *head,*p1,*p2;
    n=0;
    head=NULL;
    p1=(struct bookcard *)malloc(LEN);
    gets(p1->bookname);
    gets(p1->author);
    scanf("%d%d%d%d%f",p1->publish.year,p1->publish.month,p1->publish.day,p1->page,p1->price);
    p1->next=NULL;
    while(p1->page!=0)
    {
        n++;
        if(n==1)head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct bookcard *)malloc(LEN);
        gets(p1->bookname);
        gets(p1->author);
        scanf("%d%d%d%d%f",p1->publish.year,p1->publish.month,p1->publish.day,p1->page,p1->price);
        p1->next=NULL;
    }
    free(p1);
    return(head);
}
struct bookcard *find(struct bookcard *create,char author[20])
{
    int n,i,j,temp1,temp2,temp3;
    gets(author);
    struct bookcard *head,*p1,*p2;
    struct bookcard0 theone[500];
    head=create;
    if(head==NULL){printf("\nlist NULL\n");}
    p1=head;
    i=0;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->author,author)!=0)
        {
            p2=p1;
            p1=p1->next;
        }
        else
        {
            strcpy(theone[i].bookname,p1->bookname);
            strcpy(theone[i].author,p1->author);
            theone[i].publish.year=p1->publish.year;
            theone[i].publish.month=p1->publish.month;
            theone[i].publish.day=p1->publish.day;
            theone[i].page=p1->page;
            theone[i].price=p1->price;
            i++;
            p2=p1;
            p1=p1->next;
        }
    }
    n=i;
    for(i=0;i<n-1;i++)
        for(j=0;j<n;j++)
        {
            if(theone[i].publish.year>theone[j].publish.year)
            {
                temp1=theone[i].publish.year;
                temp2=theone[i].publish.month;
                temp3=theone[i].publish.day;
                theone[i].publish.year=theone[j].publish.year;
                theone[i].publish.month=theone[j].publish.month;
                theone[i].publish.day=theone[j].publish.day;
                theone[j].publish.year=temp1;
                theone[j].publish.month=temp2;
                theone[j].publish.day=temp3;
            }
            else
            {
                if(theone[i].publish.year==theone[j].publish.year)
                {
                    if(theone[i].publish.month>theone[j].publish.month)
                    {
                        temp1=theone[i].publish.year;
                        temp2=theone[i].publish.month;
                        temp3=theone[i].publish.day;
                        theone[i].publish.year=theone[j].publish.year;
                        theone[i].publish.month=theone[j].publish.month;
                        theone[i].publish.day=theone[j].publish.day;
                        theone[j].publish.year=temp1;
                        theone[j].publish.month=temp2;
                        theone[j].publish.day=temp3;
                    }
                    else
                    {
                        if(theone[i].publish.day>theone[j].publish.day)
                        {
                            temp1=theone[i].publish.year;
                            temp2=theone[i].publish.month;
                            temp3=theone[i].publish.day;
                            theone[i].publish.year=theone[j].publish.year;
                            theone[i].publish.month=theone[j].publish.month;
                            theone[i].publish.day=theone[j].publish.day;
                            theone[j].publish.year=temp1;
                            theone[j].publish.month=temp2;
                            theone[j].publish.day=temp3;
                        }
                    }
                }
            }
        }
    for(i=0;i<n;i++)
        printf("Book:%s\nAuthor:%s\nPublishDate:%d-%d-%d\nPage:%d\nPrice:%f\n\n",theone[i].bookname,theone[i].author,theone[i].publish.year,theone[i].publish.month,theone[i].publish.day,theone[i].page,theone[i].price);
    return(head);
}

[ 本帖最后由 雪天 于 2009-8-9 22:02 编辑 ]
搜索更多相关主题的帖子: 链表 
2009-08-09 22:01
西园竹
Rank: 5Rank: 5
等 级:职业侠客
帖 子:41
专家分:305
注 册:2009-8-8
收藏
得分:33 
你连main函数都没定义……
2009-08-09 22:17
雪天
Rank: 1
等 级:新手上路
帖 子:18
专家分:5
注 册:2009-7-23
收藏
得分:0 
回复 2楼 西园竹

一定要有main吗?
2009-08-10 08:00
西园竹
Rank: 5Rank: 5
等 级:职业侠客
帖 子:41
专家分:305
注 册:2009-8-8
收藏
得分:0 
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
1>C:\Users\ligang\Desktop\C++专用\6-3\Debug\6-3.exe : fatal error LNK1120: 1 个无法解析的外部命令
一般都说main是函数的入口,其实不是,而是编译器的某个入口调用了main函数,因此你链接生成可执行程序的时候,那个入口函数会链接main函数,你没定义当然会提示符号没定义了
2009-08-10 12:43
东海一鱼
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:48
帖 子:757
专家分:4760
注 册:2009-8-10
收藏
得分:33 
这个主要取决于你的链接工具。如楼上所说,一般情况下,c runtimer会直接调用名为main的函数作为用户的入口函数。
但是如果你的链接器支持入口符号定位,你可以修改入口为任何一个你想要直接执行的函数地址:
型如:
Link /ENTRY: MyProc


举世而誉之而不加劝,举世而非之而不加沮,定乎内外之分,辩乎荣辱之境,斯已矣。彼其于世未数数然也。
2009-08-10 13:01
灵动心境
Rank: 2
等 级:论坛游民
帖 子:12
专家分:66
注 册:2009-8-1
收藏
得分:33 
缺少函数入口函数main,要弄清楚全局变量和局部变量
2009-08-11 21:34
快速回复:一道结构体链表问题
数据加载中...
 
   



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

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