Thursday, July 30, 2009

Write a program that emulates the DOS COPY command?

it should copy the contents of a character file (such as any CPP file) to another file. Invoke the program with two command line arguments – the source file and the destination file-like this





C%26gt;ocopy srcfile.ext destfile.ext





In the program check that user has typed the correct number of command line arguments, and that the file specified can be opened. Improve on the DOS TYPE command by having the program signal an error if destination file already exist. This will prevent inadvertently writing over a valuable file

Write a program that emulates the DOS COPY command?
First thing to check with the number of arguments.. you can do it with argc and argv. argc contains the count that how many parameters are passed and argv is an array of characters which stores the argument.


Now next step check whether they are in currect format or not. choose whether u want relative path or absolute path or both.


If its directory( then you have to travel inside and check whether it exists or not ( recursively till you get filename). when you get a filename,


you have to make sure that weather file exists or not. this can be done by listing the files of present directory in a file and check ur filename is there or not.


(this you have to do for both source and dest)


Once you cleared all these steps and everything s ok.. open the source file and create the destination file,


you can use fgets, fputs to copy contents from one file to another...





Good luck


No comments:

Post a Comment