用指针的方式对一个结构数组里的元素进行删除,再显示出来,不会了,谢谢大佬
#include <stdio.h>#include <stdlib.h>
#include <string.h>
struct Tongxunlu{
char *name;
char *sex;
char *number;
};
void xianshi(struct Tongxunlu *p,int n);
void caxun1(struct Tongxunlu *p,int n);
void caxun2(struct Tongxunlu *p,int n);
void tianjia(struct Tongxunlu *p,int *n);
void shanchu(struct Tongxunlu *p,int *n);
int main(){
struct Tongxunlu student[]={
{"王明","男","13598832373"},
{"李芳","女","13243552545"},
{"李华","男","15765463662"},
{"小明","男","18842352552"},
{"小兰","女","16765645646"},
{"小王","男","17343244324"},
{"王凯","男","17743244324"}
};
int n = sizeof(student)/sizeof(student[0]);
printf("%d",n);
shanchu(student,&n);
xianshi(student,n);
return 0;
}
void xianshi(struct Tongxunlu *p,int n){
printf("%d",n);
p = (Tongxunlu*)malloc(sizeof(Tongxunlu)*n);
printf("\n\t*********班级通讯录*********\n\n");
printf("\t姓名\t性别\t 电话号码\n");
while(n--){
printf("\t%s\t %s\t%s\n",p->name,p->sex,p->number);
p++;
}
}
void shanchu(struct Tongxunlu *p,int *n){
char name[10];
int m=*n;
while(m--){
printf("\t%s\t %s\t%s\n",p->name,p->sex,p->number);
p++;
}
printf("请输入需要删除的姓名:");
scanf("%s",name);
while(m--){
if(strcmp(name,p->name)!=0){
*p=*p;
p++;
}
}
*n=*n-1;
m=m-1;
while(m--){
printf("\t%s\t %s\t%s\n",p->name,p->sex,p->number);
p++;
}
}