fopen fclose 示例解析

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>


int main(int argc, char *argv[])
{
	FILE *fp1,*fp2;
	if(argc!= 3)
	{
		printf("comand error\n");
		exit (-1);
	}

	fp1=fopen(argv[1], "r+");

	if(NULL == fp1)
	{
		perror("fopen"); 
		exit (-1);
	}

	fp2=fopen(argv[2], "w+");
	if(NULL == fp2)
	{	
		perror("fopen");
		exit (-1);
	}

	char arr[10]="abcde";
	//char arr1[10]={0};

	fread(arr, 5, 1, fp1);
	fwrite(arr, 5, 1, fp2);

	fclose(fp1);
	fclose(fp2);
	printf("\n");

	
}

你可能感兴趣的:(fopen fclose 示例解析)