题目描述 :
编写程序,每次运行时统计并显示该程序运行的次数。
如:
第1次运行,输出:第1次运行
第2次运行,输出:第2次运行
……
第n次运行,输出:第n次运行
提示:用counter.txt保存运行的次数。
本蒟蒻讲不明白题,只好直接贴代码了。
#include <stdio.h>
#include <stdlib.h>
int main ()
{
FILE *fp;
int counf;
fp = fopen("counter.txt","rb");
if (fp == NULL)
{
counf = 1;
printf ("第1次运行\n");
}
else
{
fscanf (fp,"%d",&counf);
printf ("第%d次运行\n",counf);
}
counf++;
fp = fopen("counter.txt","w+");
fprintf (fp,"%d",counf);
fclose (fp);
system ("pause");
return 0;
}
希望各位大佬手下留情。