当前位置:首页 » 编程语言 » c语言删除通讯录
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言删除通讯录

发布时间: 2022-08-12 19:07:19

① 用c语言编写通讯录,要有查询,添加,删除功能。其他不要,简单一点的

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
typedef struct{
char name[20];
int tel;

}address_list;
void Search(address_list *somebody,int n){
char ch[20];
int i = 0;
printf("请选择查询的联系人姓名:");
scanf("%s",ch);
for (; i < n; i++){
if (strcmp(ch, (*(somebody+i)).name)==0){
printf("%s的号码是%d.\n",ch,(*(somebody+i)).tel);
}

}

}
int Add(address_list *somebody){
int i,k;
printf("请输入你要添加的数目");
scanf("%d",&k);
for (i = 0; i < k; i++){
printf("请输入第%d位联系人的名称:", i + 1);
scanf("%s",(*(somebody+i)).name);
printf("请输入第%d位联系人的号码:", i + 1);
scanf("%d", &(*(somebody + i)).tel);

}
return k;
}
int Delete(address_list *somebody,int n){
char ch[20];
int i = 0;
int k = 0;
int h = 0;
printf("请选择删除的联系人姓名:");
scanf("%s", ch);
for (; i < n; i++){
if (strcmp(ch, (*(somebody + i)).name)==0){
for (k = n-1; k >i; k--){
strcpy((*(somebody + k-1)).name, (*(somebody + k)).name);
(*(somebody + k - 1)).tel = (*(somebody + k)).tel;
}
h++;
}

}

return h;
}
void main(){
address_list somebody[N];
int n=0;
int a;
S: system("cls");
A: printf("请选择你要使用的功能:\n1.添加\t2.查询\t3.删除\t4.退出\n您的选择:");

scanf("%d",&a);
switch (a)
{
case 1:
n+=Add(somebody);
break;
case 2:
Search(somebody,n);
break;
case 3:
n-=Delete(somebody,n);
break;
case 4:
goto E;
break;
default:
printf("您输入的的指令不在范围,重新输入:");
goto A;
system("pause");
break;
}
system("pause");
system("cls");
goto S;
E:
printf("程序运行结束!");
system("pause");
}

② c语言通讯录

1、去掉左右空格
2、查找@字符位置
3、位置不在开头也不在结尾

③ c语言中做一个通讯录,能够添加、删除、修改、查找

# include<stdio.h>
# include<string.h>
struct tongxun
{char name[20];
char number[20];
struct tongxun *next;
};
int all=0;
struct tongxun* tj() /*创建链表并添加成员*//**/
{
struct tongxun *head=NULL;
struct tongxun *p,*q;
system("CLS");

p=q=(struct tongxun *)malloc(sizeof(struct tongxun));

for(;;)
{printf("请输入姓名:(如果输入0则退出添加)\n");
scanf("%s",p->name);
if(!(strcmp(p->name,"0"))){ free(p);return head;}
else {printf("请输入电话号码:\n");
scanf("%s",p->number);
all++;
if(all==1)
{p->next=head;
q=p;
head=q;}
else
{p->next=NULL;
q->next=p;
q=p;
}
p=(struct tongxun *)malloc(sizeof(struct tongxun));
}
}
}
cz(struct tongxun *head) /*查找函数*/
{char name1[20],*a;
struct tongxun *p;
p=head;a=name1;
system("CLS");
printf("请输入要查找的姓名:\n");
scanf("%s",a);
while(p!=NULL)
{if((strcmp(p->name,a))==0) {printf("姓名:%s\n电话号码:%s\n",p->name,p->number);return;}
else p=p->next;
}
printf("没有此人\n");
return;
}

insert(struct tongxun *head) /*插入新成员*/
{struct tongxun* pnew;
pnew=(struct tongxun *)malloc(sizeof(struct tongxun));
while(1)
{printf("请输入姓名:(如果输入0则退出添加)\n");
scanf("%s",pnew->name);
if(!(strcmp(pnew->name,"0"))){ free(pnew);return head;}
else {printf("请输入电话号码:\n");
scanf("%s",pnew->number);
all++;
pnew->next=head;
head=pnew;
pnew=(struct tongxun *)malloc(sizeof(struct tongxun));
}
}
}
shuchu(struct tongxun *head) /*输出成员*/
{struct tongxun *p;
p=head;
printf("这里一共有%d个成员\n",all);
while(p!=NULL)
{printf("姓名:%s\n电话号码:%s\n",p->name,p->number);
p=p->next;
}
}
xg(struct tongxun *head) /*修改成员*/
{char name1[20],*a;
struct tongxun *p;
p=head;a=name1;
system("CLS");
printf("请输入要修改的姓名:\n");
scanf("%s",a);
while(p!=NULL)
{if((strcmp(p->name,a))==0) {printf("请重新输入姓名:\n");
scanf("%s",p->name);
printf("请重新输入电话号码:\n");
scanf("%s",p->number);return;}
else p=p->next;
}
printf("没有此人\n");
return;

}
sc(struct tongxun *head) /*删除成员*/
{char name1[20],*a;
struct tongxun *p,*q;
p=q=head;a=name1;
system("CLS");
printf("请输入要删除的姓名:\n");
scanf("%s",a);
while(p!=NULL)
{
if((strcmp(p->name,a))==0) {all--;q->next=p->next;return;}
else {q=p;p=p->next;}
}
printf("没有此人\n");
return;

}
void main()
{struct tongxun *head;int i;
while(1)
{printf("请选择:\n");
printf("1.添加 2.查找 3.修改 4.删除 5.插入 6.输出\n");scanf("%d",&i);
switch(i)
{case 1:head=tj();break;
case 2:cz(head);break;
case 3:xg(head);break;
case 4:sc(head);break;
case 5:insert(head);break;
case 6:shuchu(head);break;
default:printf("输入有误,请重新输入:\n");break;
}
}
}

④ c语言 通讯录 帮我增加个删除的功能

在原程序的基础上修改如下(这个程序如果用链表作,效果会更好!):

//---------------------------------------------------------------------------
#include<stdio.h>
#include<string.h>
#define N 200
int print1();

struct txl
{
char name[15];
char sex[5];
int age;
char tel[13];
char major[20];
char school[30];
char add[90];
char others[90];
};

void main()
{
int i,flag=1;
char str[15];
struct txl stu[N];

for(i=0;i<N;i++)
{
strcpy(stu[i].name,"");
strcpy(stu[i].sex,"");
stu[i].age=0;
strcpy(stu[i].tel,"");
strcpy(stu[i].major,"");
strcpy(stu[i].school,"");
strcpy(stu[i].add,"");
strcpy(stu[i].others,"");
}
for(;flag==1;)
{
switch(print1())
{
case 1:
for(i=0;stu[i].age!=0;i++)
{
if (stu[i].name[0]){ /***为配合删除而作的修改***/
printf("name: %s\nsex:%s\nage:%d\ntel:%s\nschool:%s\nmajor:%s \n",stu[i].name,stu[i].sex,stu[i].age,stu[i].tel,stu[i].major,stu[i].school,stu[i].add);
printf("others:%s\n",stu[i].others);
}
}
if(i==0)
printf("Classmates is currently empty, please enter information\n");
break;
case 2:
for(i=0;stu[i].age!=0;i++){ ;}
printf("You will now have to be carried out by the students enter information\n");
printf("please enter the name ");
scanf("%s",stu[i].name);
printf("please enter the sex ");
scanf("%s",stu[i].sex);
printf("please enter the age");
scanf("%d",&stu[i].age);
printf("please enter the tel");
scanf("%s",stu[i].tel);
printf("please enter the school");
scanf("%s",stu[i].school);
printf("please enter the major");
scanf("%s",stu[i].major);
printf("please enter the others");
scanf("%s",stu[i].others);
break;
case 3:
printf("Now you will carry out inquiries to operate! Please enter the names of the students inquiries by the end of the Enter.\n");
scanf("%s",str);
for(i=0;i<N;i++)
{
if(strcmp(stu[i].name,str)==0)
{
printf("name: %s\nsex:%s\nage:%d\ntel:%s\nschool:%s\nmajor:%s \n",stu[i].name,stu[i].sex,stu[i].age,stu[i].tel,stu[i].major,stu[i].school,stu[i].add);
printf("others:%s\n",stu[i].others);
break;
}
}
if(i==N) printf("\tClassmates did not find your classmates!\n");
break;
case 4: /******删除功能*********/
printf("Please enter the name:");
scanf("%s",str);
for (i = 0; stu[i].age; i++) {
if (!strcmp(stu[i].name,str)) {
stu[i].name[0]=0;
i=N+1;
break;
}
}
if (i==N+1) {
printf("finish!\n");
}
else printf("\tClassmates did not find your classmates!\n");
break;
case 5:
flag=0;
break;
default:
printf("Your input error, please re-enter!\n");

}

}

}
int print1()
{ int n;
printf("\t\t\t\tClassmates\n");
printf("\tWelcome to Classmates of the application, the function of the relatively thin to meet the user's general use.\n");
printf("\n");
printf("\t\t\t1.visit Classmates\n");
printf("\t\t\t2.enter information\n");
printf("\t\t\t3.demand information\n");
printf("\t\t\t4.delete information\n");
printf("\t\t\t5.exit Classmates \n");
scanf("%d",&n);
return n;
}

//---------------------------------------------------------------------------

⑤ 求,用C语言编写一个通讯录。可以更新联系人,删除联系人,查找联系人,添加联系人。要有注释。

通讯录其实就是对链表的各种操作,只要会链表,通讯录直接得了

⑥ C语言通讯录删除和寻找功能出错

scanf("%s",&xname); 应为 scanf("%s", xname); 试试

⑦ C语言编写通讯录,要求可以查找、显示、删除、添加!在线等!急!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineN100
typedefstruct{
charname[20];
inttel;

}address_list;
voidSearch(address_list*somebody,intn){
charch[20];
inti=0;
printf("请选择查询的联系人姓名:");
scanf("%s",ch);
for(;i<n;i++){
if(strcmp(ch,(*(somebody+i)).name)==0){
printf("%s的号码是%d. ",ch,(*(somebody+i)).tel);
}

}

}
intAdd(address_list*somebody){
inti,k;
printf("请输入你要添加的数目");
scanf("%d",&k);
for(i=0;i<k;i++){
printf("请输入第%d位联系人的名称:",i+1);
scanf("%s",(*(somebody+i)).name);
printf("请输入第%d位联系人的号码:",i+1);
scanf("%d",&(*(somebody+i)).tel);

}
returnk;
}
intDelete(address_list*somebody,intn){
charch[20];
inti=0;
intk=0;
inth=0;
printf("请选择删除的联系人姓名:");
scanf("%s",ch);
for(;i<n;i++){
if(strcmp(ch,(*(somebody+i)).name)==0){
for(k=n-1;k>i;k--){
strcpy((*(somebody+k-1)).name,(*(somebody+k)).name);
(*(somebody+k-1)).tel=(*(somebody+k)).tel;
}
h++;
}

}

returnh;
}
voidmain(){
address_listsomebody[N];
intn=0;
inta;
S: system("cls");
A: printf("请选择你要使用的功能: 1.添加 2.查询 3.删除 4.退出 您的选择:");

scanf("%d",&a);
switch(a)
{
case1:
n+=Add(somebody);
break;
case2:
Search(somebody,n);
break;
case3:
n-=Delete(somebody,n);
break;
case4:
gotoE;
break;
default:
printf("您输入的的指令不在范围,重新输入:");
gotoA;
system("pause");
break;
}
system("pause");
system("cls");
gotoS;
E:
printf("程序运行结束!");
system("pause");
}追问:
有一个错误啊
追答:
intDelete(address_list*somebody,intn){

charch[20];
inti=0;
intk=0;
inth=0;
printf("请选择删除的联系人姓名:");
scanf("%s",ch);
for(;i<n;i++){
if(strcmp(ch,(*(somebody+i)).name)==0){
printf("已删除姓名为%s的联系人。 ",ch);
for(k=i;k<n-1;k++){
strcpy((*(somebody+k)).name,(*(somebody+k+1)).name);
(*(somebody+k)).tel=(*(somebody+k+1)).tel;

}
h++;
}

}

returnh;
}

⑧ c语言简易通讯录按姓名删除联系人和按姓名修改联系人怎么编写

用链表应该是可以实现的