#include"stdio.h"
#include"stdlib.h"
#define FilePath "count.dat"
void writeCounter(int count,const char* path);
int readCounter(const char* path);
void main()
{
int count = 0;
count = readCounter(FilePath) + 1;
printf("该程序已运行:%d次\n", count);
printf("\n");
printf("下面将运行次数写入计数器文件(count.dat)\n");
writeCounter(count, FilePath);
printf("写入文件结束!\n");
printf("运行程序结束!\n");
printf("\n");
system("pause");
}
void writeCounter(int count, const char* path)
{
FILE* fp;
if ((fp= fopen_s(&path, "w"))==NULL)
{
printf("无法创建该文件!\n");
return;
}
fprintf(fp, "%d", count);
fclose(fp);
}
int readCounter(const char* path)
{
FILE* fp;
int count;
if ((fp = fopen_s(path, "r")) == NULL)
{
printf("没有计数器文件:count.dat,保存运行次数时将新建该文件!\n");
return 0;
}
fscanf_s(fp, "%d", &count);
fclose(fp);
return count;
}
这段代码中fopen_s应该使用那三个参数?