Saturday, 18 December 2010

Algorithm for which copies one file to another

Description:


In this program we have to use the file functions to perform the copy operation from one file to another file.

Algorithm:


Step 1: Start
Step 2: read command line arguments
Step 3: check if no of arguments =3 or not. If not print invalid no of    
              arguments
Step 4: open source file in read mode
Step 5: if NULL pointer, then print source file can not be
   open
Step 6: open destination file in write mode
Step 7: if NULL pointer, then print destination file can not be open
Step 8 : read a character from source file and write to destination file
   until EOF
Step 9: Close source file and destination file
Step 10: Stop

Output:


source.c
this is source text
ouput.c

Command line arguments source.c    ouput.c
Source.c
this is source text ouput.c
this is source text

Command line arguments source.c
Invalid number of arguments.

Conclusion: the program is error free


VIVA QUESTIONS:

1) What is file ?
Ans: The collection of alphabets is called file

2) What are the various operations performed on the file ? Ans: fopen(), fread(), fwrite(), fclose() etc..,

3) What is the use of file pointer ?
Ans: The file pointer must be used in subsequent operations on the file

No comments:

Post a Comment