filecopy.c

来自「C源码集」· C语言 代码 · 共 41 行

C
41
字号
#include <stdio.h>int main (){	char in_name[80], out_name[80];	/* with win 95 long filenames plus path names,		80 may not be big enough! */	FILE *instream, *outstream;	int ch;	printf("What is the source file name? ");	scanf("%79s", in_name);	/* %79s so only reads 79 chars and doesn't overflow the string		 in_name is name of array, ie is the address of the first element		 so don't need &in_name */	if((instream = fopen(in_name, "r")) == NULL)	{		fprintf(stderr, "open of %s for reading failed ", in_name);		perror("because");		return 1;	}	printf("What is the destination file name? ");	scanf("%79s", out_name);	if((outstream = fopen(out_name, "w")) == NULL)	{		fprintf(stderr, "open of %s for writing failed ", out_name);		perror("because");		return 1;	}	while ((ch = fgetc(instream)) != EOF)		fputc(ch, outstream);	fclose(instream);          //not strictly essentail but good practice	fclose(outstream);         // C closes files when it finishes	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?