学生通讯录,还是没有文件的。
在文件方面,我好白痴。 求大神指点。。下面是学生通讯录代码。。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct student
{
char rcord[20];
char name[20];//姓名的字节长度最大为8;
char phone[20];
char qq[20];
};
int num=0;//全局变量
struct student stu[1000];//最大可存1000个名片
void student ();//主菜单
void student1 ();//添加联系人
void student2 ();//显示通讯录
void student3 ();//查找联系人
void student3_1 ();//按姓名查找
void student3_2 ();//按学号查找
void student3_3 ();//按电话查找
void student4 ();//删除联系人
void student4_1 ();//按姓名删除
void student4_2 ();//按学号删除
void student4_3 ();//按电话删除
void main()//主函数
{
student ();
}
void student ()//主界面
{
char a;
system ("cls");
system ("color f4");
printf ("\n\n\n\n\n\n\n");
printf ("\t\t\t 【学生通讯录管理系统】\n");
printf ("================================================================================\n");
printf ("\t\t\t\t**************\n");
printf ("\t\t\t\t*1.添加联系人*\n");
printf ("\t\t\t\t*2.显示通讯录*\n");
printf ("\t\t\t\t*3.查找联系人*\n");
printf ("\t\t\t\t*4.删除联系人*\n");
printf ("\t\t\t\t*0.退出该程序*\n");
printf ("\t\t\t\t**************\n");
printf ("================================================================================\n");
scanf ("%d",&a);
switch (a)
{
case 0: break;
case 1:
{
student1 ();
student ();
break;
}
case 2:
{
student2();
break;
}
case 3:
{
student3();
student ();
break;
}
case 4:
{
student4();
student ();
break;
}
}
}
void student1 ()//添加联系人
{
int i,k;
system ("color 84");
for (i=0;i<=200;i++)
{
system ("cls");
printf ("\n\n\t输入学号\n\t");
scanf ("%s",stu[num].rcord );
printf ("\n\n\t输入姓名\n\t");
scanf ("%s",stu[num].name);
printf ("\n\n\t输入电话\n\t");
scanf ("%s",stu[num].phone);
printf ("\n\n\t输入Q Q\n\t");
scanf ("%s",stu[num].qq);
num++;
printf ("是否继续添加(1是0否)");
scanf("%d",&k);
if (k==1)
printf ("===============================================================================\n");
else
break;
}
}
void student2 ()//显示通讯录
{
system ("cls");
system ("color e0");
int i;
char k;
if (num==0)
printf ("\n\n\n\t\t\t您的通讯录为空!\n");
for (i=0;i<num;i++)
{
printf ("\n学号:%s\n姓名:%s\n电话:%s\nQ Q:%s\n",stu[i].rcord,stu[i].name,stu[i].phone,stu[i].qq);
printf ("================================================================================\n");
}
printf ("按任意键返回主菜单");
scanf ("%s",&k);
student ();
}
void student3 ()//查找联系人
{
int i;
system ("cls");
system ("color 40");
printf ("\n\n\n\n\n\n**************************************\n");
printf ("\t\t1按姓名查找\n");
printf ("\t\t2按学号查找\n");
printf ("\t\t3按电话查找\n");
printf ("**************************************\n");
printf ("请选择:(按其他数字键返回!)");
scanf ("%d",&i);
switch (i)
{
case 1:
{
student3_1 ();
break;
}
case 2:
{
student3_2 ();
break;
}
case 3:
{
student3_3 ();
break;
}
}
}
void student3_1 ()//按姓名查找
{
int k,n;
char name[20];
printf ("请输入姓名:");
scanf ("%s",&name);
for (k=0;k<num;k++)
{
if (strcmp(stu[k].name,name)==0)
{
printf ("\n\t学号:%s\n",stu[k].rcord);
printf ("\n\t姓名:%s\n",stu[k].name);
printf ("\n\t电话:%s\n",stu[k].phone);
printf ("\n\tQ Q:%s\n",stu[k].qq);
}
}
printf ("是否继续查找(1是0否)");
scanf ("%d",&n);
if (n==1)
student3 ();
else
student ();
}
void student3_2 ()//按学号查找
{
int k,n;
char rcord[20];
printf ("请输入学号:");
scanf ("%s",&rcord);
for (k=0;k<num;k++)
{
if (strcmp(stu[k].rcord,rcord)==0)
{
printf ("\n\t学号:%s\n",stu[k].rcord);
printf ("\n\t姓名:%s\n",stu[k].name);
printf ("\n\t电话:%s\n",stu[k].phone);
printf ("\n\tQ Q:%s\n",stu[k].qq);
}
}
printf ("是否继续查找(1是0否)");
scanf ("%d",&n);
if (n==1)
student3 ();
else
student ();
}
void student3_3 ()//按电话查找
{
int k,n;
char phone[20];
printf ("请输入电话:");
scanf ("%s",&phone);
for (k=0;k<num;k++)
{
if (strcmp(stu[k].phone,phone)==0)
{
printf ("\n\t学号:%s\n",stu[k].rcord);
printf ("\n\t姓名:%s\n",stu[k].name);
printf ("\n\t电话:%s\n",stu[k].phone);
printf ("\n\tQ Q:%s\n",stu[k].qq);
}
}
printf ("是否继续查找(1是0否)");
scanf ("%d",&n);
if (n==1)
student3 ();
else
student ();
}
void student4 ()//删除联系人
{
int i;
system ("cls");
system ("color 60");
printf ("\n\n\n\n\n\n**************************************\n");
printf ("\t\t1按姓名删除\n");
printf ("\t\t2按学号删除\n");
printf ("\t\t3按电话删除\n");
printf ("**************************************\n");
printf ("请选择:(按其他数字键返回!)");
scanf ("%d",&i);
switch (i)
{
case 1:
{
student4_1 ();
break;
}
case 2:
{
student4_2 ();
break;
}
case 3:
{
student4_3 ();
break;
}
}
}
void student4_1 ()//按姓名删除
{
int i,k,n,a;
char name[20];
printf ("请输入姓名:");
scanf ("%s",&name);
for (k=0;k<num;k++)
{
if (strcmp(stu[k].name,name)==0)
{
printf ("\n\t学号:%s\n",stu[k].rcord);
printf ("\n\t姓名:%s\n",stu[k].name);
printf ("\n\t电话:%s\n",stu[k].phone);
printf ("\n\tQ Q:%s\n",stu[k].qq);
printf ("确定要删除给联系人!(1是0否)");
scanf ("%d",&i);
if (i==1)
{
for (a=k;a<num-1;a++)
stu[a]=stu[a+1];
num--;
}
break;
}
}
printf ("是否继续删除(1是0否)");
scanf ("%d",&n);
if (n==1)
student4 ();
else
student ();
}
void student4_2 ()//按学号删除
{
int i,k,n,a;
char rcord[20];
printf ("请输入学号:");
scanf ("%s",&rcord);
for (k=0;k<num;k++)
{
if (strcmp(stu[k].rcord,rcord)==0)
{
printf ("\n\t学号:%s\n",stu[k].rcord);
printf ("\n\t姓名:%s\n",stu[k].name);
printf ("\n\t电话:%s\n",stu[k].phone);
printf ("\n\tQ Q:%s\n",stu[k].qq);
printf ("确定要删除给联系人!(1是0否)");
scanf ("%d",&i);
if (i==1)
{
for (a=k;a<num-1;a++)
stu[a]=stu[a+1];
num--;
}
}
}
printf ("是否继续删除(1是0否)");
scanf ("%d",&n);
if (n==1)
student4 ();
else
student ();
}
void student4_3 ()//按电话删除
{
int i,k,n,a;
char phone[20];
printf ("请输入电话:");
scanf ("%s",&phone);
for (k=0;k<num;k++)
{
if (strcmp(stu[k].phone,phone)==0)
{
printf ("\n\t学号:%s\n",stu[k].rcord);
printf ("\n\t姓名:%s\n",stu[k].name);
printf ("\n\t电话:%s\n",stu[k].phone);
printf ("\n\tQ Q:%s\n",stu[k].qq);
printf ("确定要删除给联系人!(1是0否)");
scanf ("%d",&i);
if (i==1)
{
for (a=k;a<num-1;a++)
stu[a]=stu[a+1];
num--;
}
}
}
printf ("是否继续删除(1是0否)");
scanf ("%d",&n);
if (n==1)
student4 ();
else
student ();
}