一道结构体链表问题
原题:图书馆的图书检索卡记载的内容包括:书名、作者姓名、出版日期、页数、定价等内容。根据上述内容定义一个结构体类型,并按照作者姓名进行查找,按照出版日期顺序从远到近打印出该作者的所有著作。
程序错误:
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 编辑 ]