同学录程序代码(英文提示版)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

同学录程序代码

(英文提示版)

By AzxXiner

#include

#include

#include

#define STU_INFO_FILE "F:\\课程\\C语言程序设计\\大型实验1-班级同学录\\classmates_info_file.txt" //定义文本信息存储路径

#define FAILURE 0xFFFFFFFF

#define SUCCESS !0xFFFFFFFF

#define MAX_STU_COUNT 99

void output(int index);

void outputall(void);

int find(__int64 mobile,__int64 QQ);

int insert(int index);

int remove(int index);

char name[MAX_STU_COUNT][10+1]; //存放姓名,每个班级50人,名字最长为10个字符;

char email[MAX_STU_COUNT][20+1]; //存放姓名,每个班级50人,名字最长为10个字符;

__int64 student_number[MAX_STU_COUNT]; //学号过长,即便unsigned int也不够存储,采用64位整型;

__int64 mobile_phone_number[MAX_STU_COUNT];

__int64 qq_number[MAX_STU_COUNT];

char student_number_char[13 + 1];

char mobile_phone_number_char[11 + 1];

char qq_number_char[10 + 1];

int information_number=0;//索引信息条数变量

int AddStuInfoFromFile()

{

int tmpi;

FILE * pFile = NULL;

pFile = fopen(STU_INFO_FILE, "r");//打开文件

if(!pFile)

{

printf("AddStuInfoFromFile: File Open Failed!\n");

return FAILURE;

}

else

printf("AddStuInfoFromFile: File Open Succeeded!\n");

memset(student_number,0,8);

memset(mobile_phone_number,0,8);

memset(qq_number,0,8);

memset(name,0,MAX_STU_COUNT * (10 + 1));

memset(email,0,MAX_STU_COUNT * (20 + 1)); //清零

for(tmpi = 0; tmpi < MAX_STU_COUNT; tmpi++)

{

fscanf(pFile,"%s",student_number_char);//也可用%I64d作为转义序列直接读取64位整型数

fscanf(pFile,"\t%s",name[tmpi]);

fscanf(pFile,"\t%s",mobile_phone_number_char);

fscanf(pFile,"\t%s",email[tmpi]);

fscanf(pFile,"\t%s\n",qq_number_char);

student_number[tmpi] = _atoi64(student_number_char);

mobile_phone_number[tmpi] = _atoi64(mobile_phone_number_char);

qq_number[tmpi] = _atoi64(qq_number_char);

information_number = tmpi;//存储信息索引条数

/*

printf("name %d is %s\n", tmpi, name[tmpi]);

printf("email %d is %s\n", tmpi, email[tmpi]);

printf("qq_number %d is %I64d\n",tmpi, qq_number[tmpi]);

*/

}

fclose(pFile);//关闭文件,保存数据

return SUCCESS;

}

void outputAll()

{

int tmpi;

tmpi = AddStuInfoFromFile();

printf("tmpi is %d\n", tmpi);

for(tmpi = 0; tmpi < information_number; tmpi++)

{

printf("%I64d\t%s\t%I64d\t%s\t%I64d\n", student_number[tmpi], name[tmpi],

mobile_phone_number[tmpi], email[tmpi],qq_number[tmpi]);

}

}

int main()

{

int choose;//选择菜单功能序号

int index;//通讯录索引信息序号

int subscript; //函数返回的下标

__int64 mobile,QQ; //查找函数的参数

outputAll();

for(;;)

{

printf("\nMEUN: 1.Find 2.Insert 3.Delete 4.Output All Information 5.Stop\n");

printf("Enter 1 to 5 to choose a function.Please Enter A Number: ");

scanf("%d",&choose);

switch(choose)

{

case 1:

printf("\nPlease Enter Tne Mobile Or QQ Or Both Of Them To Find."

"Enter 0 To Replace One Of Them If You Don't Remember.""\nPlease Enter: ");

scanf("%I64d,%I64d",&mobile,&QQ);

subscript = find(mobile,QQ);

//output(subscript);

break;

case 2:

printf("\nEnter The Place-number Where You Want To Insert Information(It Must Be Smaller Than %d): ",information_number+1);

scanf("%d",&index);

subscript = insert(index);

相关文档
最新文档