
基本能满足你的要求!!
代码如下:
#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=0j<=i+1j++)
if(strcmp(c1,p[j].name)==0)
{p[j]=p[j+1]
l=j}
while(l<i+1)
{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=pp=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=pp=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
}
C语言编写一个通讯录管理系统的源代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*定义保存通迅录的信息*/
structfriends
{
charname[20]/*名字*/
charprovince[20]/*省份*/
charcity[20]/*所在城市*/
charnation[20]/*民族*/
charsex[2]/*性别M/F*/
intage/*年龄*/
}
扩展资料
1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。
2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。
3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)