2022-10-9

1.要求创建一个time.txt,存储内容格式如下:
[1] 2022-07-28 17:15:06
[2] 2022-07-28 17:15:07
[3] 2022-07-28 17:15:08
ctrl + c退出程序,过一会儿之后重新启动程序

[3] 2022-07-28 17:15:08 <-------------------
[4] 2022-07-28 17:16:31
[5] 2022-07-28 17:16:32

#include 
#include 
#include 
#include 
int main(int argc,const char *argv[])
{FILE *fp = fopen("time.txt","a+");if(NULL == fp){perror("fopen time.txt");return -1;}int n = 0;char c = ' ';while((c = fgetc(fp)) >= 0){if('\n' == c){n++;}}time_t t;while(1){n++;time(&t);struct tm *info = localtime(&t);printf("[%d] %d-%02d-%02d  %02d:%02d:%02d\n",\n,\info->tm_year+1900,\info->tm_mon+1,\info->tm_mday,\info->tm_hour,\info->tm_min,\info->tm_sec\);fprintf(fp,"[%d] %d-%02d-%02d  %02d:%02d:%02d\n",\n,\info->tm_year+1900,\info->tm_mon+1,\info->tm_mday,\info->tm_hour,\info->tm_min,\info->tm_sec\);fflush(fp);sleep(1);}return 0;
}

2..readwrite拷贝一张图片

#include 
#include 
#include 
#include 
int main(int argc,const char *argv[])
{FILE *fp = fopen("1.jpg","r");FILE *fp2 = fopen("2.jpg","w+");if(NULL == fp || NULL == fp2){perror("fopen png");return -1;}char temp = ' ';while((fread(&temp,1,1,fp)) > 0){fwrite(&temp,1,1,fp2);}return 0;
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部