当前位置: 首页> 文旅> 旅游 > 广州11个区繁华排名_美工设计培训_网站快速优化排名_自媒体

广州11个区繁华排名_美工设计培训_网站快速优化排名_自媒体

时间:2025/7/11 7:50:17来源:https://blog.csdn.net/m0_73504072/article/details/142961764 浏览次数:0次
广州11个区繁华排名_美工设计培训_网站快速优化排名_自媒体

问题

通过 fwrite和 fread去拷贝 文件到另外一个文件上 

#include<myhead.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<errno.h>
#include<time.h>
int main(int argc, const char *argv[])
{
FILE *fp =fopen(argv[1],"r");
if(fp==NULL)
{
perror("-1");
return 0;}
char arr[100]=" ";
int res=0;
FILE *op=fopen(argv[2],"w+");
if(op==NULL)
{perror("-1");
return -1;}
while((res=fread(arr,1,sizeof(arr),fp))>0)
{
fwrite(arr,1,res,op);}}

向文件中每一秒打印当前系统时间

include<myhead.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<errno.h>
#include<time.h>
typedef  struct times
{
int year;
int month;
int day;
int hour;
int min;
int sec;
int d;
} ss;
int getss(FILE*fp)
{
char b[256]=" ";
int a=0;
while(fgets(b,sizeof(b),fp)!=NULL)
{sscanf(b,"%d",&a);
}
return a;
}
int main(int argc, const char *argv[])
{time_t sys_time =0;int c=0;int a=-1;FILE *fp=fopen("suhui.txt","r");
if(fp==NULL)
{fp=fopen("suhui.txt","w+");}else
{ c=getss(fp);fclose(fp);
fp=fopen("suhui.txt","w+");}if(fp==NULL){perror("-1");}if(c==0){c=1;}else{c++;}
while(1)
{ time(&sys_time);ss s;struct tm *tm_ptr=localtime(&sys_time);
s.year=tm_ptr->tm_year+1900;
s.month=tm_ptr->tm_mon+1;
s.day= tm_ptr->tm_mday;
s.hour=tm_ptr->tm_hour;
s.min=tm_ptr->tm_min;
s.sec=tm_ptr->tm_sec;
if(s.sec!=a)
{fprintf(fp," %d.0 %4d-%2d-%2d %2d:%2d:%2d\n ",c,s.year,s.month,s.day,s.hour,s.min,s.sec );
fflush(fp);
c++;}a=s.sec;
}
fclose(fp);
return 0;}

3. fgets去计算\n

#include<myhead.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<errno.h>
#include<time.h>
int main(int argc, const char *argv[])
{
FILE *fp =fopen(argv[1],"r");
if(fp==NULL)
{
perror("-1");
return 0;}
char arr[100]=" ";
int res=0;
FILE *op=fopen(argv[2],"w+");
if(op==NULL)
{perror("-1");
return -1;}
while((res=fread(arr,1,sizeof(arr),fp))>0)
{
fwrite(arr,1,res,op);}
fclose(fp);
fclose(op);
fp=fopen(argv[2],"r");
char b[20]=" ";int h=0;
while(1)
{char *t=fgets(b,sizeof(b),fp);
if(t==NULL)
{break;}
if(b[strlen(b)-1]=='\n')
{
h++;}}printf("%d",h);}

关键字:广州11个区繁华排名_美工设计培训_网站快速优化排名_自媒体

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: