當前位置:首頁 » 編程語言 » 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語言簡易通訊錄按姓名刪除聯系人和按姓名修改聯系人怎麼編寫

用鏈表應該是可以實現的