#include<myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp;
if((fp=fopen("./work.txt","a+"))==NULL)
{
perror("fopen error");
return -1;
}
int count=0;
int flag=0;
char buf;
//记录行数
while((buf=fgetc(fp)) != EOF)
{
//对buf进行判断
if(buf == '\n')
{
count++;
}
}
fprintf(fp,"关闭程序重新运行\n");
while(flag!=3)
{
count++;
//定义一个系统时间变量
time_t sysTime = time(NULL);
//定义时间结构体指针,执行时间
struct tm *tm_ptr = localtime(&sysTime);
fprintf(fp,"%d、%02d:%02d:%02d\n",count,tm_ptr->tm_hour,\
tm_ptr->tm_min,\
tm_ptr->tm_sec);
flag++;
sleep(1);
}
fclose(fp);
return 0;
}
8.16作业
最新推荐文章于 2024-11-14 21:21:03 发布