大家帮我运行下这个,看看结果
先在D盘下创建一个 记事本 qq.txt 输入几个数字,随便几个都行, 最后一个的时候打一个空格 ,保存好,运行程序,看看输出结果中是不是最后一个 数字重复了!
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
#define SIZE sizeof(snode)
typedef struct student
{
int num;
struct student *next;
struct student *prior;
}snode;
snode *create1();
void print(snode *head);
void main(void)
{
snode *head1;
printf("\n链表为:\n");
head1=create1();
printf("\n链表为:\n");
print(head1);
}
snode *create1()
{
snode *head,*r,*s;
FILE *fp;
int num1;
head=(snode *)malloc(sizeof(SIZE));
head->next=head->prior=NULL;
r=head;
fp=fopen("D:\\qq.txt","r");
while(!feof(fp))
{
fscanf(fp,"%d",&num1);
s=(snode *)malloc(sizeof(SIZE));
s->num=num1;s->next=NULL;s->prior=r;
r->next=s;
r=s;
}
return head;
}
void print(snode *head)
{
snode *p;
p=head->next;
while(p!=NULL)
{
printf("%6d",p->num);
p=p->next;
}
}