#include<stdio.h>
#include<string.h> /*包含字符串处理函数的头文件,可以直接调用现有的字符串处理的一系列函数了*/
#include<iostream>
using namespace std;
typedef struct //定义结构体
{
char score; /*编号*/
char name[10]; /*姓名*/
char num[15]; /*号码*/
char email[20];/*邮箱*/
char age[8];/*年龄*/
char adds[20];/*住址*/
}
Person;
Person pe[80];
int menu_select()
{
char c;
do {
system("cls");
printf("\t\t *****通讯录***** \n");
printf("\t\t┌───────┐\n");
printf("\t\t│ 1. 添加记录 │\n");
printf("\t\t│ 2. 显示记录 │\n");
printf("\t\t│ 3. 删除记录 │\n");
printf("\t\t│ 4. 查询记录 │\n");
printf("\t\t│ 5. 修改记录 │\n");
printf("\t\t│ 6. 保存记录 │\n");
printf("\t\t│ 0. 退出程序 │\n");
printf("\t\t└───────┘\n");
printf("\t\t请您选择(0-6):");
c = getchar();
} while (c<'0' || c>'6');
return(c - '0');
}
void OpenTxt(Person per[], int n)
{
char filename[255];
printf("\t请输入所保存的文件名:");
scanf("\t%s", filename);
FILE *pFile = fopen(filename, "r+");
char *pBuf;
fseek(pFile, 0, SEEK_END);
int len = ftell(pFile);
pBuf = new char[len + 1];
rewind(pFile);
fread(pBuf, 1, len, pFile);
pBuf[len] = 0;
puts(pBuf);
fclose(pFile);
system("pause");
}
int Input(Person per[], int n)
{
int i = 0;
char sign = 'a';
char x[10];
while (sign != 'n' && sign != 'N')
{
printf("\t编号:");
scanf("\t%d", &per[n + i].score);
printf("\t姓名:");
scanf("\t%s", per[n + i].name);
printf("\t年龄:");
scanf("\t%s", per[n + i].age);
printf("\t电话号码:");
scanf("\t%s", per[n + i].num);
printf("\t通讯住址:");
scanf("\t%s", per[n + i].adds);
printf("\t电子邮箱:");
scanf("\t%s", per[n + i].email);
fputs(fgets(x, 10, stdin), stdout);
printf("\n\t是否继续添加?(Y/N)");
scanf("\t%c", &sign);
i++;
}
return(n + i);
}
void Display(Person per[], int n) /* per数组存放通讯录信息,n为通讯录行数 */
{
OpenTxt(pe, n);
if (n <= 0)
return;
int i;
printf("-----------------------