FILE COPYING

/                 /*  FILE COPYING  */

#include<stdio.h>
#include<stdlib.h>
void main()
  {
    FILE *fp1,*fp2;
    int i;
    clrscr();
    printf("\n\t\tINPUT:");
    printf("\n\t\t------");
    printf("\n\t\tCreated a text file name as sample.txt
       with the content like 'This is my first program.'");
    if((fp1=fopen("D:\sample.txt","r"))==NULL)
     {
       printf("Cannot open file\n");
       exit(1);
     }
    if((fp2=fopen("D:\sampledup.txt","w"))==NULL)
     {
       printf("cannot open file\n");
       exit(1);
     }
    while((i=getc(fp1))!=EOF)
       putc(i,fp2);
    fclose(fp1);
    fclose(fp2);
    printf("\n\t\tOUTPUT:");
    printf("\n\t\t-------");
    printf("\n\t\tThe text copied into file sampledup.txt
                                      as follows\n");
    printf("\n\t\t");
    fp2=fopen("D:\sampledup.txt","r");
     while((i=getc(fp2))!=EOF)
        putchar(i);
    fclose(fp2);
    getch();
  }

INPUT:
------
Created a text file name as sample.txt with the content like This is my first program.

OUTPUT:
-------
The text copied into file sampledup.txt as follows
This is my first program.

1 comment:

odellabdo said...

Mohegan Sun Arena tickets - KTNV
Tickets for events at 창원 출장샵 Mohegan Sun 사천 출장샵 Arena 의왕 출장샵 can be 공주 출장샵 purchased at Ticketmaster.com or by calling the Arena at 1-888-226-4700. 문경 출장안마

Related Posts with Thumbnails