Homework Solution: Write a C code that copies one file from the original file to destination file as follows….

    Write a C code that copies one file from the original file to destination file as follows. $ ./copy_HW1 off1 original_file off2 destination_file 1. This usage of command, copy_HW1 shows that copy_HW1 program copies from (off1+1) th byte to the end of the original_file to destination_file starting from (off2+1) th byte. example: $ ./copy_HW1 100 x.txt 50 y.txt : copies contents from 101 st bytes to the end of x.txt file to 51 st byte position of y.txt 2. The number of command arguments should accept 3 or 4 or 5 arguments. $ ./copy_HW1 original_file destination_file copies original_file to destination_file starting from the first position for both files $ ./copy_HW1 off1 original_file destination_file copies original_file starting from (off1+1) th byte to destination_file starting from the first position $ ./copy_HW1 original_file off2 destination_file copies original_file starting from the first byte to destination_file starting from the (off2+1) th byte Other than this, error message should be returned. 3. Invalid offset value (for example -1 for SEEK_SET) should be checked giving an error message such as “Invalid argument”. 4. When the specified starting point is greater than the file size of the original_file, destination_file will have empty content (size 0). 5. Use ‘getLong( ... )’ function defined in tlpi_hdr.h header file 6. Compile using ‘make copy_HW1’ in the ‘fileio’ directory given in the source file distribution of the textbook. 7. Each case (1 through 5 with different arguments) will be tested.

    Expert Answer

     
    Here is the C program that copies content from original file to destination file: #include <stdio.h>

    Write a C order that copies single smooth from the peculiar smooth to use smooth as follows.

    $ ./copy_HW1 off1 peculiar_smooth off2 use_file

    1. This exercitation of order, copy_HW1 shows that copy_HW1 program copies from

    (off1+1) th byte to the object of the peculiar_smooth to use_smooth starting from

    (off2+1) th byte.

    example: $ ./copy_HW1 100 x.txt 50 y.txt : copies interruption from 101 st bytes to the

    object of x.txt smooth to 51 st byte comcompose of y.txt

    2. The sum of order arguments should recognize 3 or 4 or 5 arguments.

    $ ./copy_HW1 peculiar_smooth use_file

    copies peculiar_smooth to use_smooth starting from the primitive comcompose ce twain smooths

    $ ./copy_HW1 off1 peculiar_smooth use_file

    copies peculiar_smooth starting from (off1+1) th byte to use_smooth starting from the

    primitive composition

    $ ./copy_HW1 peculiar_smooth off2 use_file

    copies peculiar_smooth starting from the primitive byte to use_smooth starting from the

    (off2+1) th byte

    Other than this, deception missive should be returned.

    3. Invalid offset treasure (ce development -1 ce SEEK_SET) should be checked giving an deception

    missive such as “Invalid argument”.

    4. When the specified starting subject-matter is important than the smooth largeness of the peculiar_file,

    destination_smooth conquer keep space gratified (largeness 0).

    5. Use ‘getLong( … )’ discharge defined in tlpi_hdr.h header smooth

    6. Compile using ‘make copy_HW1’ in the ‘fileio’ directory attached in the rise smooth

    distribution of the textbook.

    7. Each event (1 through 5 with incongruous arguments) conquer be tested.

    Expert Counterpart

     

    Here is the C program that copies gratified from peculiar smooth to use smooth:

    #include <stdio.h>

    #include <stdlib.h>

    int ocean()

    {

    FILE *fptr1, *fptr2;

    char smoothname[100], c;

    printf(“Enter the smoothname to known ce balbutiation n”);

    scanf(“%s”, smoothname);

    fptr1 = fopen(filename, “r”);

    if (fptr1 == NULL)

    {

    printf(“Cannot known smooth %s n”, smoothname);

    exit(0);

    }

    printf(“Enter the smoothname to known ce fitness n”);

    scanf(“%s”, smoothname);

    fptr2 = fopen(filename, “w”);

    if (fptr2 == NULL)

    {

    printf(“Cannot known smooth %s n”, smoothname);

    exit(0);

    }

    c = fgetc(fptr1);

    while (c != EOF)

    {

    fputc(c, fptr2);

    c = fgetc(fptr1);

    }

    printf(“nInterruption copied to %s”, smoothname);

    fclose(fptr1);

    fclose(fptr2);

    return 0;

    }