求助 请大家看一看这个程序哪里有问题 请改一下
1.注册登录时密码不对也可以进去2.执行删除功能时程序出错停止工作
#include "stdafx.h"
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define n 20
struct person
{
char name[20]; /*姓名*/
char yx[15];//邮箱
int f; /*分类*/
char QQ[20]; /*QQ*/
char wx[40]; /*微信*/
char ph[15]; /*联系电话*/
struct person *next;
};
char ch, *menu[] = { "------------------通讯录菜单---------------",
"1.----------建立通讯录-----------------",
"2.----------输出全部通讯录-------------",
"3.----------增加的联系人的个数---------------",
"4.----------删除指定号码的人-------------",
"5.----------按姓名查找联系人信息-------------",
"6.----------按分类查找联系人信息-------------",
"7.----------按姓名排序---------------------",
"0.----------导出txt信息--------------------",
"9.----------退出通讯录---------------------" };
void zhuce();
void denglu();
struct person *input();
void print(struct person *h);
struct person *insert(struct person *h);
struct person *del(struct person *h);
void find4(struct person *h);
void find3(struct person *h);
void export_info(struct person *h);
int menu_select();
//void PX(struct person *h);
char yhm[n],mm[n];
int main(int argc, char* argv[])
{
int i;int flag;
printf("-----------\n1.注册\n2.登陆\n3.退出\n");
scanf("%d",&i);
switch(i)
{ case 0: break;
case 1 : zhuce();denglu();flag=1;break;
case 2: denglu();flag=1; break;
}
if(flag==1)
{
struct person *head = NULL;
for (;;)
{
switch (menu_select())
{
case 1:head = input(); break;
case 2:print(head); break;
case 3:head = insert(head); break;
case 4:head = del(head); break;
case 5:find3(head); break;
case 6:find4(head); break;
case 7:export_info(head); break;
case 9:exit(0);
}
}
}
return 0;
}
void zhuce( )
{char temp1[n],temp2[n],temp3[n],yhmtmp[n];
printf("输入用户名\n");
fflush(stdin);//清空缓存
gets(yhmtmp);
printf("输入密码\n");
fflush(stdin);
gets(temp1);
printf("输入密码确认\n");
fflush(stdin);
gets(temp2);
if(!strcmp(temp1,temp2))
{
strcpy(mm,temp1); printf("注册成功\n");
}
else
{ printf("输入密码确认\n");
gets(temp3);
if(!strcmp(temp1,temp3))
{
strcpy(mm,temp1); printf("注册成功\n");
}
else
printf("注册失败\n");
}
}
void denglu( )
{
char s1[n],s2[n];
printf("输入用户名\n");
fflush(stdin);
gets(s1);
printf("输入密码\n");
fflush(stdin);
gets(s2);
if((strcmp(s1,yhm))&&(strcmp(s2,mm)))
printf("登陆成功\n");
}
struct person *input() /*输入函数*/
{
int r;
printf("请输入你要建立的通讯录的人数:\n");
scanf("%d", &r);
struct person *h = NULL, *p, *q = h;
int i;
for (i = 1; i <= r; i++)
{
printf("请依次输入第%d个人的姓名,分类(1-办公 2-个人 3-商务),QQ,微信,邮箱,联系电话:\n", i);
p = (struct person *)malloc(sizeof(struct person));
if (p == NULL)
{
printf("内存不足!\n");
exit(0);
}
scanf("%s%d%s%s%s%s", p->name, &p->f, p->QQ, p->wx, p->yx, p->ph);
if (i == 1)h = p;
else q->next = p;
q = p;
}
q->next = NULL;
return h;
}
void print(struct person *h) /*输出函数*/
{
struct person *p = h;
while (p)
{
printf("联系人信息:\n%s,%d,%s,%s,%s,%s\n", p->name, p->f, p->QQ, p->wx, p->yx, p->ph);
p = p->next;
}
}
struct person *insert(struct person *h) /*增联系人信息*/
{
int v;
printf("请输入你要增加的联系人的个数:\n");
scanf("%d", &v);
struct person *p, *r;
int i;
for (i = 1; i <= v; i++)
{
r = (struct person *)malloc(sizeof(struct person));
printf("请输入第%d个你要插入的联系人的信息:\n", i);
scanf("%s%d%s%s%s%s", r->name, &r->f, r->QQ, r->wx, r->yx, r->ph);
p = h;
h = r;
r->next = p;
}
return h;
}
struct person *del(struct person *h) /*按号码进行删除*/
{
char r[15];
printf("请输入要删除的人的号码:\n");
scanf("%s",&r);
struct person *p, *q = h;
if (h = NULL)printf("empty list!\n");
else
{
p = h;
while (p->ph != r&&p->next)
{
q = p; p = p->next;
}
if (p->ph == r)
{
if (h == p)h = p->next;
else q->next = p->next;
}
else printf("%ld is not found!\n",r);
}
return h;
}
void find3(struct person *h) /*按姓名查找*/
{
char ss[10];
printf("请输入要查找的联系人的姓名:\n");
scanf("%s", ss);
struct person *p;
if (h == NULL)printf("empty list!\n");
else
{
p = h;
while (p)
{
if (strcmp(p->name, ss) == 0)
printf("联系人信息:\n %s %d %s %s %s %s\n", p->name, p->f, p->QQ, p->wx, p->yx, p->ph);
p = p->next;
}
}
}
void find4(struct person *h) /*按分类查找*/
{
int num;
printf("请输入要查找的学生的分类(1-办公 2-个人 3-商务):\n");
scanf("%d", &num);
struct person *p;
if (h == NULL)printf("empty list!\n");
else
{
p = h;
while (p)
{
if (p->f == num)
{ printf("学生信息:\n %s %s %s %s %s\n", p->name, p->QQ, p->wx, p->yx, p->ph);
if(p->f==1) printf("办公");
if(p->f==2) printf("个人");
if(p->f==3) printf("商务");
}
else
printf("没有你要查找的联系人信息!\n");
p = p->next;
}
}
}
void export_info(struct person *h) /*按号码查找*/
{
int num;
FILE *fp = fopen("d:\\record.txt", "w+");;
struct person *p;
if (h != NULL)
{
p = h;
while (p)
{
fprintf(fp,"学生信息:\n%s %d %s %s %s %s\n",p->name, p->f, p->QQ, p->wx, p->yx, p->ph);
p = p->next;
}
}
fclose(fp);
}
int menu_select()
{
int i, s;
char c[3];
for (i = 0; i<11; i++)
printf("%s\n", menu[i]);
do
{
scanf("%s", c);
s = atoi(c);
} while (s<0 || s>9);
return s;
}