#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc, const char *argv[])
{
FILE *q=fopen("get.c","a+");
int i=0;
/* while(fgetc(q)=='\n')
{
i++;
}
i--;*/
time_t t; //time(&t)
struct tm *p=NULL;
printf("提示\n");
while(1)
{
t=time(NULL);
p=localtime(&t);
fprintf(q,"%d-%02d-%02d %02d:%02d:%02d",p->tm_year+1900,p->tm_mon+1,p->tm_mday, p->tm_hour,p->tm_min,p->tm_sec);
//fflush(stdout);
sleep(1);
}
if(fclose(q)<0)
{
perror("close");
return -3;
}
return 0;
}
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
if(argc < 2)
{
printf("没有输入文件名\n");
}
int fd = open("./1111.png",O_RDONLY);
int fe = open(argv[1],O_RDWR|O_CREAT|O_TRUNC,0775);
char c;
if(fd < 0 || fe<0)
{
printf("打开文件失败\n");
return -1;
}
while(read(fd,&c,1))
{
write(fe,&c,1);
}
close(fd);
close(fe);
return 0;
}
————————————————
版权声明:本文为CSDN博主「来日定方长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_56095954/article/details/126044497