Sunday, 19 December 2010

Algorithm To merge the contents of two files into a third file

Description:

The program will read the contents of two given files and stores them in the third   given file

Algorithm:

Step1: read the first filename to read from
Step2: read the second filename to read from
Step3: read the third filename to store the contents of the two files
Step4: open file1 and file2 in read mode
Step5:if any of the file doesn’t open exit
Step6:open file3 in write mode
Step7:if any error occurs exit

Step8:read character by character from file1  and write to file3 until end of file is      reached

Step9: read character by character from file2 and write to file3 until end of file is      reached

Step10:print the merging is successfull

Step11:stop



Output:

Enter the name of the file 1 Red1
Enter the name of the file 2 Red2
Enter the name of the file 3 Red3

Two files were merged into the file Red3  successfully


Enter the name of the file 1 file1
Enter the name of the file 2 Red2
Enter the name of the file 3 Red3

Error file1 doesn’t exist



Enter the name of the file 1 Red1
Enter the name of the file 2 file2
Enter the name of the file 3 Red3

Error file2 doesn’t exist


Enter the name of the file 1 Red1
Enter the name of the file 2 Red2
Enter the name of the file 3 file3


Error file3 doesn’t exist



Conclusion : The progam is error free

No comments:

Post a Comment