1.使用fread和fwrite完成两个文件的拷贝
#include<myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp=NULL;
if((fp=fopen("./zhanmusi.bmp","r"))==NULL)
{
perror("fopen error");
return -1;
}
//fseek(fp,54,SEEK_SET);//3200054
char str[3200054]="";
fread(str,1,3200054,fp);
fclose(fp);
FILE *fp1=NULL;
if((fp1=fopen("./zhanmusi","w"))==NULL)
{
perror("fopen error");
return -1;
}
fwrite(str,1,3200054,fp1);
fclose(fp1);
return 0;
}
2.使用read、write完成两个文件的拷贝
#include<myhead.h>
int main(int argc, const char *argv[])
{
int fd=-1;
if((fd=open("./zhangmusilongduo.bmp",O_RDONLY))==-1)
{
perror("fopen error");
return -1;
}
//fseek(fp,54,SEEK_SET);//3200054
char str[1141814]="";
read(fd,str,1141814);
close(fd);
int fd1=-1;
if((fd1=open("./zhangmusilongduo",O_WRONLY|O_CREAT,0664))==-1)
{
perror("fopen error");
return -1;
}
write(fd1,str,1141814);
close(fd1);
return 0;
}
3.将时间在文件中跑起来
#include<myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp=NULL;
if((fp=fopen("./time.txt","a+"))==NULL)
{
perror("fopen error");
return -1;
}
FILE *fp1=NULL;
if((fp1=fopen("./line.txt","a+"))==NULL)
{
perror("fopen error");
return -1;
}
int a=0,b,c;
char str[128]="";
while(1)
{
time_t sysTime=time(NULL);
struct tm *t=localtime(&sysTime);
if( fgetc(fp1)==EOF )
a++;
else
{
a=fgetc(fp1);
a++;
}
fputc(a,fp1);
c=fprintf(fp,"第%d行 %d : %d : %d\n",a,t->tm_hour,t->tm_min,t->tm_sec);
fseek(fp,-c,SEEK_CUR);
fgets(str,sizeof(str),fp);
fputs(str,stdout);
b=t->tm_sec;
while(1){
sysTime=time(NULL);
t=localtime(&sysTime);
if( (b+1==t->tm_sec) || (b+t->tm_sec==60) )
break;
}
}
fclose(fp);
fclose(fp1);
return 0;
}