# include <stdio.h>
# include <conio.h>
void main()
{
char c ;
FILE *fptr1, *fptr2, *fptr3 ;
clrscr() ;
printf("Enter the text to be stored in the file - 1.\n") ;
printf("Use ^Z or F6 at the end of the text and press
ENTER : \n\n") ;
fptr1 = fopen("FIRST.DAT","w") ;
while((c = getc(stdin)) != EOF)
fputc(c, fptr1) ;
fclose(fptr1) ;
printf("\nEnter the text to be stored in the file - 2.\n") ;
printf("Use ^Z or F6 at the end of the text and press
ENTER : \n\n") ;
fptr2 = fopen("SECOND.DAT","w") ;
while((c = getc(stdin)) != EOF)
fputc(c, fptr2) ;
fclose(fptr2) ;
fptr1 = fopen("FIRST.DAT","r") ;
fptr2 = fopen("SECOND.DAT","r") ;
fptr3 = fopen("MERGE.DAT","w") ;
while((c = fgetc(fptr1)) != EOF)
fputc(c, fptr3) ;
fclose(fptr1) ;
while((c = fgetc(fptr2)) != EOF)
fputc(c, fptr3) ;
fclose(fptr2) ;
fclose(fptr3) ;
printf("\nThe content of the merged file is : \n\n") ;
fptr3 = fopen("MERGE.DAT", "r") ;
while((c = fgetc(fptr1)) != EOF)
putchar(c) ;
fclose(fptr3) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter the text to be stored in the file - 1.
Use ^Z or F6 at the end of the text and press ENTER :
Computer Practice - I
I - Semester
^Z
Enter the text to be stored in the file - 2.
Use ^Z or F6 at the end of the text and press ENTER :
Computer Practice - II
II - Semester
^Z
The content of the merged file is :
Computer Practice - I
I - Semester
Computer Practice - II
II - Semester
No comments:
Post a Comment