啊呀!!谁来帮帮我啊 !!!
看不懂!指针还没学到!哪位大大能帮我翻译成数组的啊?万分感谢!!!#define LEN sizeof(struct TXJL)
#define NULL 0
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
struct PHONE
{ int firstNum;
long secondNum;
};
struct TXJL
{
char name[10];
struct PHONE phone;
struct TXJL *next;
};
void Help()
{
printf("---------系统声明----------\n");
printf("本系统是由。。。。。。开发\n");
printf("欢迎批评指正.联系邮件:。。。。。。。。\n");
}
void fmenu()
{ system("cls");
printf("通讯录管理系统\n");
printf("1.输入初始数据录入\n");
printf("2.文件载入数据\n");
printf("3.表头插入数据\n");
printf("4.表尾插入数据\n");
printf("5.删除数据\n");
printf("6.显示数据\n");
printf("7.查找数据\n");
printf("8.保存数据到文件\n");
printf("0.退出\n");
printf("Auducy!\n");
}
struct TXJL *create_txl()
{ struct TXJL *head,*tail,*p;
int i=0;head=tail=NULL;
while (1)
{ p=(struct TXJL*)malloc(LEN);
printf("输入第%d个姓名:",i+1);
scanf("%s",p->name);
if(!strcmp(p->name,"#"))break;
printf("输入其手机号码前3位:");
scanf("%d",&p->phone.firstNum);
printf("输入其手机号码后8位:");
scanf("%ld",&p->phone.secondNum);
p->next=NULL;
if(i==0)
{ head=tail=p;i++;}
else
{tail->next=p;
tail=p ;
i++;
}
};
free(p);
return (head);
}
void print_txl(struct TXJL*head)
{ struct TXJL*p;
p=head;
if (head!=NULL)
do
{
printf("%s-----%d-----%ld\n",p->name,p->phone.firstNum,p->phone.secondNum);
p=p->next;
}while(p!=NULL);
}
void outData(struct TXJL*p)
{
printf("%s-----%d-----%8d\n",p->name,p->phone.firstNum,p->phone.secondNum);
}
struct TXJL *read_txl(char*pFileName)
{
int i=0;
struct TXJL *p;
struct TXJL *tail;
struct TXJL *head;
FILE*fp;
fp=fopen(pFileName,"r");
if(fp==NULL)
{
printf("Cannot open file!\n");
exit(0);
}
else
{do
{ p=(struct TXJL*)malloc(LEN);
fscanf(fp,"%s%3d%ld",&(p->name),&(p->phone.firstNum),&(p->phone.secondNum));
p->next=NULL;
if(!strcmp(p->name,"#"))break;
if(i==0)
{ head=tail=p;
i++;
}
else
{tail->next=p;
tail=p;
i++;
}
}while(1);
free(p);
return(head);
}
}
struct TXJL*insert_txl1(struct TXJL*head,struct TXJL*p)
{ struct TXJL*q=head;
struct TXJL*pre;
p->next=NULL;
if(head==NULL)head=p;
else
{ while(q->next!=NULL)
{ pre=q;
q=q->next;
}
q->next=p;
}
return (head);
}
struct TXJL *insert_txl2(struct TXJL *head,struct TXJL*p)
{ p->next=NULL;
if(head==NULL)head=p;
else
{ p->next=head;
head=p;
}
return(head);
}
struct TXJL*delete_txl(struct TXJL*head,char*pName)
{ struct TXJL*q,*p=head;
if(!strcmp(pName,head->name))
{head=head->next;
free(p);
}
else
{ do
{q=p;
if(!strcmp(pName,p->name))break;
p=p->next;
}while(p->next!=NULL);
if((p!=NULL)&&!strcmp(pName,p->name))
{ q->next=p->next;
free(p);
}
else printf("不存在姓名是%s的结点!\n",pName);
}
return(head);
}
struct TXJL*find_txl1(struct TXJL*head,char *pName)
{ struct TXJL*p;
p=head;
while((p!=NULL)&&strcmp(p->name,pName))
p=p->next;
if(p) return(p);
else return(NULL);
}
struct TXJL*find_txl2(struct TXJL*head,long n)
{ struct TXJL *p;
p=head;
while((p!=NULL)&&(p->phone.secondNum!=n))
p=p->next;
if(p) return(p);
else return(NULL);
}
void write_txl(struct TXJL*head,char *pFileName)
{
FILE*fp;
struct TXJL *p;
p=head;
fp=fopen(pFileName,"w");
if(head!=NULL)
do
{fprintf(fp,"%10s %d %ld\n",p->name,p->phone.firstNum,p->phone.secondNum);
p=p->next;
}while(p!=NULL);
fprintf(fp,"# ");
fclose(fp);
}
void main()
{ char str[80];
struct TXJL*head,*p;
int x,k,n;
Help();
fmenu();
scanf("%d",&x);
while(x!=0)
{
switch(x)
{ case 1:
head=create_txl();
write_txl(head,"D:\\TXJL.txt");
break;
case 2:
printf("Auducy!\n");
head=read_txl("D:\\TXJL.txt");
break;
case 3:
printf("Auducy!\n");
printf("输入插入结点的值:\n");
p=(struct TXJL*)malloc(LEN);
printf("输入插入结点的姓名:");
scanf("%s",p->name);
printf("输入其手机号码前3位:");
scanf("%d",&p->phone.firstNum);
printf("输入其手机号码后8位:");
scanf("%ld",&p->phone.secondNum);
head=insert_txl2(head,p);
break;
case 4:
printf("输入插入结点的值:\n");
p=(struct TXJL*)malloc(LEN);
printf("输入插入结点的姓名:");
scanf("%s",p->name);
printf("输入其手机号码前3位:");
scanf("%d",&p->phone.firstNum);
printf("输入其手机号码后8位:");
scanf("%ld",&p->phone.secondNum);
head=insert_txl1(head,p);
break;
case 5:
getchar();
printf("输入删除结点的姓名:\n");
scanf("%s",str);
head=delete_txl(head,str);
break;
case 6:
head=read_txl("D:\\TXJL.txt");
print_txl(head);
break;
case 7:
system("cls");
printf("1.按姓名查找\n");
printf("2.按电话查找\n");
scanf("%d",&k);
if(k==1)
{ getchar();
printf("输入要查找的姓名:\n");
scanf("%s",str);
p=find_txl1(head,str);
if(p)
{ printf("存在,输出如下:\n");
outData(p);
}
}
else
{ printf("输入要查找的电话号码后8位:\n");
scanf("%ld",&n);
p=find_txl2(head,n);
if (p)
{ printf("存在,输出如下:\n");
outData(p);}
}
break;
case 8:
write_txl(head,"D:\\TXJL.txt");
break;
case 9:
exit(0);
}
printf("按任意键继续\n");
printf("Auducy!\n");
getchar();
getchar();
system("cls");
fmenu();
scanf("%d",&x);
}
}