这个是我编的,用数组和链表两种功能实现的通讯录
基本能满足你的要求!!
代码如下:
#include "stdlib.h"
#define NEW (struct node *)malloc(sizeof(struct node))
struct student
{ char name[10],tel[11];
}a[20];
struct node
{ char name[20],tel[11];
struct node *next;
};
main()
{ struct student *jianli(),*delete(struct student *);
struct student *charu(struct student *);
void xianshi(struct student *);
struct node *create(),*delnode(struct node*,char *);
struct node *insert(struct node *,struct node *,char *);
void prlist(struct node *);
struct student *p;
struct node *head=NULL,*stu;
char s[80],name[20],q[80];
int c,w;
a:;
system("cls");
printf("\nEnter your choice\n");
printf("1.SHUZU\n2.LIANBIAO\n0.Quit\n");
gets(q);
w=atoi(q);
switch(w)
{ case 1:
do
{ do
{ printf("----------------------------------------------\n");
printf("******************Phone book******************\n");
printf("----------------------------------------------\n");
printf(" | | <1> Add a note | |\n");
printf(" | | <2> Show the list | |\n");
printf(" | | <3> Delete a note | |\n");
printf(" | | <4> Insert a note | |\n");
printf(" | | <0> Quit | |\n");
printf("----------------------------------------------\n");
printf(" Enter your choice(0-4):");
gets(s);
c=atoi(s);
}while(c<0||c>4);
system("cls");
switch(c)
{ case 1: p=jianli();break;
case 2: xianshi(p);break;
case 3: printf("\nPlease input the name to deleted\n");
p=delete(p);break;
case 4: printf("\nPlease input the new name\n");
p=charu(p);break;
}
}while(c);goto a;
case 2:
do
{ do
{printf("----------------------------------------------\n");
printf("******************Phone book******************\n");
printf("----------------------------------------------\n");
printf(" | | <1> Add a note | |\n");
printf(" | | <2> Show the list | |\n");
printf(" | | <3> Delete a note | |\n");
printf(" | | <4> Insert a note | |\n");
printf(" | | <0> Quit | |\n");
printf("----------------------------------------------\n");
printf(" Enter your choice(0-4):");
gets(s);
c=atoi(s);
}while(c<0||c>4);
system("cls");
switch(c)
{ case 1: head=create();break;
case 2: prlist(head);break;
case 3: printf("\nInput the name to deleted\n");
gets(name);
head=delnode(head,name);break;
case 4: stu=NEW;
printf("\nInput the new node\n");
printf("name:");
gets(stu->name);
printf("tel:");
gets(stu->tel);
stu->next=NULL;
printf("\nInsert position\n");
printf("name:");
gets(name);
head=insert(head,stu,name);
}
}while(c);goto a;
}
}
#include "string.h"
struct student *jianli()
{ char c1[10],c2[11];
int i=0;
printf("name:");
gets(c1);
while(strlen(c1)!=0)
{ strcpy(a[i].name,c1);
printf("tel:");
gets(c2);
strcpy(a[i].tel,c2);
i++;
printf("name:");
gets(c1);
}
return a;
}
#include "string.h"
struct student *delete(struct student *p)
{ char c1[10];
int i=0,j,l=0;
while(strlen(p[i].name)!=0)
i++;
printf("name:");
gets(c1);
for(j=0;j<=i+1;j++)
if(strcmp(c1,p[j].name)==0)
{p[j]=p[j+1];
l=j;}
while(l {p[l]=p[l+1];
l++;}
return p;
}
#include "string.h"
struct student *charu(struct student *p)
{ char c1[10],c2[11];
int i=0;
while(strlen(p[i].name)!=0)
i++;
printf("name:");
gets(c1);
strcpy(p[i].name,c1);
printf("tel:");
gets(c2);
strcpy(p[i].tel,c2);
return p;
}
#include "string.h"
void xianshi(struct student *p)
{ int i=0;
printf("name\ttel\n\n");
while(strlen(p[i].name)!=0)
{ printf("%s\t%s\n",p[i].name,p[i].tel);
i++;}
}
#include "stdlib.h"
#include "string.h"
#define NEW (struct node *)malloc(sizeof(struct node))
struct node *create()
{ struct node *h;
struct node *p,*q;
char name[20];
h=q=NULL;
printf("name:");
gets(name);
while(strlen(name)!=0)
{ p=NEW;
if(p==NULL)
{ printf("Allocation failure\n");
exit(0);
}
strcpy(p->name,name);
printf("tel:");
gets(p->tel);
p->next=NULL;
if(h==NULL)
h=p;
else
q->next=p;
q=p;
printf("name:");
gets(name);
}
return h;
}
struct node *insert(struct node *head,struct node *p0,char *x)
{ struct node *p,*q;
if(head==NULL)
{ head=p0;
p0->next=NULL;
}
else
{ p=head;
while(strcmp(x,p->name)!=0&&p->next!=NULL)
{ q=p;p=q->next;}
if(strcmp(x,p->name)==0)
{ if(p==head)
head=p0;
else
q->next=p0;
p0->next=p;
}
else
{ p->next=p0;
p0->next=NULL;
}
}
return head;
}
void prlist(struct node *head)
{ struct node *p;
p=head;
printf("name\ttel\n\n");
while(p!=NULL)
{ printf("%s\t%s\n",p->name,p->tel);
p=p->next;
}
}
struct node *delnode(struct node *head,char *x)
{ struct node *p,*q;
if(head==NULL)
{ printf("this is a empty list.");
return head;
}
p=head;
while(strcmp(x,p->name)!=0&&p->next!=NULL)
{ q=p;p=p->next;}
if(strcmp(x,p->name)==0)
{ if(p==head)
head=p->next;
else
q->next=p->next;
free(p);
}
else
printf("Not found.");
return head;
}
嘿嘿,我要500块!
除非你给我钱。。否则我才不写咧。。这个软件。涉及到好多东西。
300块就帮你写。。。谁叫你上课不认真了。。高中就学会了的东西
RMB服务拿来问 居然还出30分 楼主可以的