io第二天

	FILE *fp=fopen("2.c","r");
	if(NULL == fp)
	{
		ERR_MSG("fopen");
		return -1;
	}
	printf("fopen success");	
	
	FILE *fq=fopen("4.txt","w");
	if(NULL == fp)
	{
		ERR_MSG("fopen");
		return -1;
	}
	printf("fopen success");
	size_t res=0;
	char t;
	while(1)
	
	{
		res=fread(&t,1,1,fp);
		if(0 == res)
			break;
		fwrite(&t,1,1,fq);

	}


	return 0;

io第二天_第1张图片

 

int main(int argc, const char *argv[])
{
	FILE *fp=fopen("2.c","r");
	if(NULL == fp)
	{
		printf("__%d__\n",__LINE__);
		perror("fopen");
		return -1;
	}
	FILE *fq=fopen("3.txt","w");

	printf("fopen success");
	char buf[20]="";
	int sum=0;  //计算字符数
	int len=0;  //计算行数
	while(1)
	{	
		if(fgets(buf,sizeof(buf),fp)== NULL)
			break;
		fputs(buf,fq);
		printf("%s",buf);
		sum+=strlen(buf);
		for(int i=0;i<=strlen(buf);i++)
		{
			if (buf[i]!='\n')
				continue;
			len++;
		}
	}
		printf("%d\n",sum);
		printf("%d\n",len);



	if(fclose(fp)<0)
	{
		perror("fclose");
		return -1;
}
	printf("关闭成功\n");
	return 0;
}

 

你可能感兴趣的:(java,前端,javascript)