|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- /*
- 内存池
- */
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- struct Contact
- {
- char name[128];
- char num[128];
- struct Contact *next;
- };
- void addPerson(struct Contact **head,int n);
- void findPerson(struct Contact *head,int n);
- void changePerson(struct Contact *head,int n);
- void delPerson(struct Contact **head,char *target);
- void displayContact(struct Contact *head,int n);
- void getinput(struct Contact *head);
- void getinput(struct Contact *head)
- {
- printf("请输入联系人姓名:");
- scanf("%s",head->name);
- printf("\n请输入联系人电话号码:");
- scanf("%s",head->num);
- }
- void addPerson(struct Contact **head,int n)
- {
- struct Contact *current;
- static struct Contact *tail;
-
- current = (struct Contact *)malloc(sizeof(struct Contact));
- getinput(current);//填充节点信息
-
- if (*head != NULL)
- {
- tail->next = current;
- current->next = NULL;
- }
- else//空链表,即第一次输入的时候
- {
- *head = current;
- current->next = NULL;
- }
- tail = current;
- }
- void delPerson(struct Contact **head,char *target)
- {
- struct Contact *current,*previous,*start;
- previous = NULL;
- current = *head;
- start = *head;
- int i,k;
-
- printf("\n目标:%s",target);
- i = (target != current->name || target != current->num);
- printf("\ni ===== %d\n",i);
- if (*head != NULL) //链表有节点
- {
-
- while(current != NULL && (target != current->name || target != current->num)) //current == NULL 或 匹配成功为假
- {
- //printf("1循环i = %d",i);
- previous = current;printf("成功1 \n");
- current = current->next;printf("成功2\n");
- //k = !(!(strcmp(target,current->name)) || !(strcmp(target,current->num)));printf("成功3");
- // printf("\n2循环i = %d",i);
- }
-
- if (current == NULL) //找到最后还是没找到
- {
- printf("\n没有找到目标");
- }
- else
- {
- if (previous == NULL) //只有一个节点
- {
- *head = current->next;
- printf("\n删除成功");
- }
- else
- {
- previous->next = current->next;
- printf("\n删除成功");
- }
- }
-
- }
- else //空链表
- {
- printf("\n通讯录里没有成员");
- }
- }
- int main (void)
- {
- struct Contact *head = NULL;
- int n = 0;
-
- while(1)
- {
- printf("\n请输入对应的数字:1.插入 2.查找 3.更改 4.删除 5.显示所有 -1.退出\n");
- scanf("%d",&n);
-
- if (n == 1)
- {
-
- addPerson(&head,n);printf("成功1 ");
- printf("\n添加成功");
-
- }
- else if (n == 2)
- {
-
- }
- else if (n == 3)
- {
-
- }
- else if (n == 4)
- {
- char what[128];
- printf("请输入成员名称或电话:");
- scanf("%s",what);
-
- delPerson(&head,what);
-
- }
- else if (n == 5)
- {
-
- }
- else if (n == -1)
- {
- break;
- }
- else
- {
-
- }
- }
-
- return 0;
- }
复制代码
大家帮我看看第61行的 i 不管匹配不匹配它都是返回1. |
|