struct Txl
{
char name[20];
long long tel;
struct Txl *next;
};
int n;
struct Txl creat(void)
{
struct Txl *p1,*p2,*head;
n=0;
p1=p2=(struct Txl)malloc(LEN);
memset(p1,0,sizeof(LEN));
memset(p2,0,sizeof(LEN));
printf("姓名\t");
scanf("%s",&p1->name);
fflush(stdin);
printf("电话\t");
scanf("%lld",&p1->tel);
fflush(stdin);
head=NULL;
while(p1->tel!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Txl*)malloc(LEN);
memset(p1,0,sizeof(LEN));
printf("姓名\t");
scanf("%s",&p1->name);
fflush(stdin);
printf("电话\t");
scanf("%lld",&p1->tel);
fflush(stdin);
}
p2->next=NULL;
return(head);
}
void prin(struct Txl *head){...}//输出。。。
void save(struct Txl *head)
{
int i;
struct Txl *p;
FILE *fp;
p=head;
if((fp=fopen("1.txt","wb"))==NULL)
{
printf("不能打开文件");
return;
}
for(i=0;i<n;i++)
{
if(fwrite(p,LEN,1,fp)!=1)
{
printf("写入失败");
}
p=p->next;
}
fclose(fp);
}
void main(){...}