C语言简单示例(文件读写3)

#include<stdio.h>
void main(int argc,char *argv[])
{
	FILE *fpRead, *fpWrite;
	char ch;

	if(argc == 1)
	{
		printf("have not enter file name strike any key exit");
		getch();
		exit(0);
	}

	if((fpRead = fopen(argv[1],"rt")) == NULL)
	{
		printf("Cannot open %s\n",argv[1]);
		getch();
		exit(1);
	}
	if(argc == 2)
	{
		fpWrite = stdout;
	}
	else if ((fpWrite = fopen(argv[2],"wt+")) ==NULL)
	{
		printf("Cannot open %s\n",argv[2]);
	}
	while((ch = fgetc(fpRead)) != EOF)
	{
		fputc(ch,fpWrite);
	}

	fclose(fpRead);
	fclose(fpWrite);
}


你可能感兴趣的:(C语言简单示例(文件读写3))