📄 pb_engine.c
字号:
#include "../sys_headfile.h"
#include "pb_engine.h"
#include "pb_main.h"
/*读电话本文件*/
void readPhonebookFile(void)
{
FILE *fp = NULL;
//open file
if((fp = fopen(PHONEBOOK_FILE,"r")) == NULL)
{
//no file or open error
printf ("\nSystem Message :Cant't open the file");
printf ("\nIf you first use this ,The system don't have the file");
printf ("\nSysrem will create the file to save data");
//create a new file
if ((fp = fopen(PHONEBOOK_FILE,"w")) == NULL)
{
printf ("\nCreate File ERROR");
return ;
}
fclose (fp);
}
//read file to struct
if ( fread(&contacts,sizeof(contacts),1,fp) == 1)
{
fclose (fp);
}
//read file error
else
{
printf("\nRead the file Error or no data\n");
fclose (fp);
return ;
}
}
/*写电话本文件*/
void writePhonebookFile(void)
{
FILE *fp = NULL;
//open file
if ( (fp = fopen(PHONEBOOK_FILE,"w")) == NULL)
{
printf ("\nOpen the file Error(write)");
return ;
}
//write file
if (fwrite(&contacts,sizeof(contacts),1,fp) == 1)
{
fclose (fp);
return ;
}
//write file error
else
{
printf ("\nwrite the file error");
fclose (fp);
return ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -