Task
Your task is to write a file archive utility similar to that of the Unix tar program. This program will be a command line
program (i.e. there will be no graphical user interface). The purpose of this file archive utility is to allow users and
system administrators alike to back up specific parts of their Linux file system into a single file. Backing up file
systems in this way is common practice and especially useful in disaster/recovery scenarios where the resulting file can
be taken away on a removable media (typically a magnetic tape).
The implementation of this software, at every stage, must include methods for checking and handling errors.

Stage 1
Write a file archive utility which can:

Archive one or more files (each specified at the commend line) into a file.
Extract all of the file


can anyone help me or give me ideas where to start looking or any materials i need to read ?

Okay, so you basically need to read filenames from the command line, then copy those contents into an archive file.

Here is a small piece of code that might help:

int main(int argc, char *argv[])
{
    FILE *file_archive, *fp;

    /* let "archive" be the archive file */
    if ( (file_archive = fopen("arhive", "w")) == NULL ) {
        printf("\nError");
    } else {
        for (i = 1; i <= argc - 1; i++) {
            if ( (fp = fopen(argv[i]) == NULL) {
                printf("\nError");
            } else {
            /**
             * Here, extract contents from the file, then write it into the archive file.
             * The next file specified is opened in the next iteration.
             **/             
            }
         }
    }   

    return 0;
}

PS: For reading contents of file, you could use fread() or any other function. Extract the contents and then write it into the archive file

I have the exact same piece of coursework, can you help me please?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.