pb_engine.c

来自「基于minigui的智能手机pda源码」· C语言 代码 · 共 62 行

C
62
字号
#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 + =
减小字号Ctrl + -
显示快捷键?