1.思维导图
2.
#ifndef _HEAD_H_
#define _HEAD_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define PRINT_ERROR(mesg) do{perror(mesg);return -1;}while(0)
#endif
int main(int argc, const char *argv[])
{
FILE* fp=fopen("./time.txt","a+");
if(fp==NULL)
{
PRINT_ERROR("fopen");
}
int count=0;
char buf[128];
while(fgets(buf,sizeof(buf),fp)!=0)
{
count++;
}
printf("%d\n",count);
fclose(fp);
while(1)
{
FILE* fp=fopen("./time.txt","a+");
time_t t=time(NULL);
struct tm *now=localtime(&t);
count++;
if(now==NULL)
PRINT_ERROR("localtime error");
fprintf(fp,"%d %d-%d-%d %02d:%02d:%02d\n",count,now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);
printf("%d %d-%d-%d %02d:%02d:%02d\n",count,now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);
fclose(fp);
sleep(1);
}
return 0;
}
3.
#ifndef _HEAD_H_
#define _HEAD_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define PRINT_ERROR(mesg) do{perror(mesg);return -1;}while(0)
#endif
int main() {
FILE* fp=fopen("~/图片/'2025-03-04 01-13-52 的屏幕截图.png'","r");
if(fp==NULL)
{
PRINT_ERROR("fopen");
}
FILE* fp2=fopen("~/图片/'2025-03-04 01-13-52 的屏幕截图.png'","w");
if(fp2==NULL)
{
PRINT_ERROR("fopen");
}
char buf[128]={0};
while(fread(buf,sizeof(buf),1,fp)!=0)
{
if(fwrite(buf,sizeof(buf),1,fp2)==0)
return -1;
}
fclose(fp);
fclose(fp2);
printf("FINISH\n");
return 0;
}