例13.2将一个磁盘文件中的信息复制到另一个磁盘文件中。
#include <stdio.h>
main( )
{FILEin,out;
char ch,infile[10],outfile[10];
printf("Enter the infile name:\n");
scanf("%s",infile);
printf("Enter the outfile name:\n");
scanf("%s",outfile);
if((in=fopen(infile,"r"))==NULL)
{printf("cannot open infile\n");
exit(0);

if((out=fopen(outfile,"w"))==NULL)
{printf("cannot open outfile\n");
exit(0);

   while(!feof(in))fputc(fgetc(in),out);
fclose(in);
fclose(out);

运行情况如下:
Enter the infile name:
file1.c(输入原有磁盘文件名)
Enter the outfile name:
file2.c (输入新复制的磁盘文件名)
程序运行结果是将file1.c文件中的内容复制到file2.c中去。可以用下面DOS命令验证
c>type file1.c
computer and c(file1.c中的信息)
c>type file2.c
computer and c (file2.c中的信息)