求指点。关于从文件中将数据初始化到链表中的一些问题
最近在做一个彩票系统的设计,从文件初始化数据到堆中开辟的链表时,会发现一些问题,程序有点小长,求大家指点一下。。小弟研究了很久,这个两个几乎相同的代码从文件中读数据到链表以后,打印出的结果完全不一样。typedef struct Ticket
{
int Ticket_ID:; //中奖号码
int Ticket_Type; //彩票类型
float Ticket_Price; //彩票价格
int Ticket_Status; //彩票是否开奖
int Tikcet_Dayth; //期号
flota Ticket_Total_Money //奖池余额
struct Ticket *Next_Ticket;
}TI;
typedef struct Person
{
char Person_ID[20]; //彩民账号
char Person_Name[20]; //彩民姓名
char Person_Password[20]; //彩民密码
float Person_Balance; //彩民账号余额
struct Person *Next_Person;
}PE;
void Print_Person_Link(PE *Person_Head)
{
PE *Person_Temp = Person_Head;
while(Person_Temp != NULL)
{
print("%s %s %s %f\n", Person_Temp->Person_ID, Person_Temp->Person_Name, Person_Temp->Person_Password, Person_Temp->Person_Balance);
Person_Temp = Person_Temp->Next_Person;
}
}
void Print_Ticket_Link(TI *Ticket_Head)
{
TI *Ticket_Temp = Ticket_Head;
while(Ticket_Temp != NULL)
{
print("%d %d %f %d %d %f", Ticket_Temp->Ticket_ID, Ticket_Temp->Ticket_Type, Ticket_Temp->Ticket_Price, Ticket_Temp->Ticket_Status, Ticket_Temp->Ticket_Dayth, Ticket_Temp->Ticket_Total_Money);
Ticket_Temp = Person_Temp->Next_Ticket;
}
}
PE *Person_File_Initial(PE *Person_Head)
{
FILE *Person_File = NULL;
PE *Person_File = NULL;
if((Person_File = fopen("Person_File.txt", "r")) == NULL)
{
printf("目前没有彩民注册.......\n");
}
else
{
while(!feof(Person_File))
{
PE *Person_New_Node = (PE *)malloc(sizeof(PE));
if(Person_Head == NULL)
{
Person_Head = Person_New_Node;
}
else
{
Person_Temp->Next_Person = Person_New_Node;
}
Person_Temp = Person_New_Node;
Person_New_Node->Next_Person = NULL;
fscanf(Person_File, "%s %s %s %f", Person_New_Node->Person_ID, Person_New_Node->Person_Name, Person_New_Node->Person_Password, &Person_New_Node->Person_Balance);
}
Print_Person_Link(Person_Head); //这是打印链表所有数据的一个函数,这个函数小弟已经用了N次,保证没有任何问题
fclose(Person_File);
return Person_Head;
}
TI *Ticket_File_Initial(TI *Ticket_Head)
{
FILE *Ticket_File = NULL;
TI *Ticket_Temp = NULL;
if((Ticket_File = fopen("Ticket_File.txt", "r")) == NULL)
{
printf("目前没有开奖信息.......\n");
}
else
{
while(!feof(Ticket_File))
{
TI *Ticket_New_Node = (TI *)malloc(sizeof(TI));
if(Ticket_Head == NULL)
{
Ticket_Head = Ticket_New_Node;
}
else
{
Ticket_Temp->Next_Ticket = Ticket_New_Node;
}
Ticket_Temp = Ticket_New_Node;
Ticket_New_Node->Next_Ticket = NULL;
fscanf(Ticket_File, "%d %d %f %d %d %f", &Ticket_New_Node->Ticket_ID, &Ticket_New_Node->Ticket_Type, &Ticket_New_Node->Ticket_Price, &Ticket_New_Node->Ticket_Status, &Ticket_New_Node->Ticket_Dayth, &Ticket_New_Node->Ticket_Total_Money);
}
Print_Ticket_Link(Ticket_Head); //这是打印链表所有数据的一个函数,这个函数小弟已经用了N次,保证没有任何问题
fclose(Ticket_File);
return Ticket_Head;
}
int main()
{
PE *Person_Head = NULL;
TI *Person_Head = NULL;
Person_Head = Person_File_Initial(Person_Head);
Ticket_Head = Ticket_File_Initial(Ticket_Head);
return 0;
}
Person_File.txt 里的内容
aaa 1 11111 84.000000
bbb 2 22222 88.000000
ccc 3 33333 70.000000
ddd 4 44444 90.000000
Ticket_File.txt 里的内容
17 1 2.000000 1 1 986.000000
20 2 4.000000 1 1 966.000000
19 3 6.000000 1 1 966.000000
运行以后的结果是
aaa 1 11111 84.000000
bbb 2 22222 88.000000
ccc 3 33333 70.000000
ddd 4 44444 90.000000
0.000000 //这里为什么多了一行0?
//然后光标就停止在这一行不动了,如果不立刻停止程序,系统将死机
请大家指点一下。。。纠结了一天了,实在没有办法,才来论坛上求助的~~~~~~
[ 本帖最后由 tczxq88 于 2012-2-17 21:50 编辑 ]