#include <stdio.h>
#include <string.h>
#include <stdlib.h>
FILE *fd_door_cfg;
unsigned short door_open_mode,door_off_dly;
int main(int argc, char *argv[])
{
int res,i;
char u8Buff[100],u8Buff1[100],s,*ptr;
long int fc;
// ------------打开开门授权方式配置文件,如果不存在创建文件,并写入缺省密码开门授权
printf("begin! \n");
fd_door_cfg = fopen("./doorconfig.txt","r+");
if(fd_door_cfg == NULL)
{//如果打不开文件,那么创建文件,并写入缺省值 1 (密码)
printf("doorconfig.txt not exist! \n");
fd_door_cfg = fopen("./doorconfig.txt","w+");
if(fwrite("door open mode = password\n", sizeof("door open mode = password\n"),1, fd_door_cfg) != 1)
printf("write doorconfig.txt error! \n");
if(fwrite("Off delay = 15\n", sizeof("Off delay = 15\n"),1 ,fd_door_cfg) != 1)
printf("write doorconfig.txt error! \n");
printf("doorconfig.txt creat! \n");
}
else
printf("doorconfig.txt exist! \n");
fclose(fd_door_cfg);
fd_door_cfg = fopen("./doorconfig.txt","r+");
printf("file open!\n");
i = 0;
fc = ftell(fd_door_cfg);
printf("%d\n",fc);
fgets(u8Buff,100,fd_door_cfg);
fc = ftell(fd_door_cfg);
printf("%d LINE = %s\n",fc,u8Buff);
fgets(u8Buff1,100,fd_door_cfg);
fc = ftell(fd_door_cfg);
printf("%d LINE = %s\n",fc,u8Buff1);
//{
//
printf("LINE = %s\n",u8Buff);
//}
//printf("read first line = %.s\n",u8Buff);
//fgets(&u8Buff[0],100,fd_door_cfg);
//printf("read second line = %s\n",u8Buff);
if(strcmp(u8Buff,"door open mode = password") == 0)
door_open_mode = 1;
else if(strcmp(u8Buff,"door open mode = card") == 0)
door_open_mode = 0;
else if(strcmp(u8Buff,"door open mode = card | password") == 0)
door_open_mode = 2;
else if(strcmp(u8Buff,"door open mode = card & password") == 0)
door_open_mode = 3;
else
door_open_mode = 1;
//fgets(&u8Buff[0],200,fd_door_cfg);
//printf("read second line = %s\n",u8Buff);
//door_off_dly = atoi(ptr);
//printf("open mode = %x, off dly = %d\n",door_open_mode,door_off_dly);
fclose(fd_door_cfg);
return 0;
}