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 regulation that copies individual finish from the peculiar finish to intention finish as follows.

    $ ./copy_HW1 off1 peculiar_finish off2 intention_file

    1. This usage of instruct, copy_HW1 shows that copy_HW1 program copies from

    (off1+1) th byte to the object of the peculiar_finish to intention_finish starting from

    (off2+1) th byte.

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

    object of x.txt finish to 51 st byte aspect of y.txt

    2. The number of instruct arguments should confirm 3 or 4 or 5 arguments.

    $ ./copy_HW1 peculiar_finish intention_file

    copies peculiar_finish to intention_finish starting from the primary aspect ce twain finishs

    $ ./copy_HW1 off1 peculiar_finish intention_file

    copies peculiar_finish starting from (off1+1) th byte to intention_finish starting from the

    primary aspect

    $ ./copy_HW1 peculiar_finish off2 intention_file

    copies peculiar_finish starting from the primary byte to intention_finish starting from the

    (off2+1) th byte

    Other than this, deception notice should be returned.

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

    notice such as “Invalid argument”.

    4. When the fixed starting top is senior than the finish dimension of the peculiar_file,

    destination_finish succeed bear space full (dimension 0).

    5. Use ‘getLong( … )’ exercise defined in tlpi_hdr.h header finish

    6. Compile using ‘make copy_HW1’ in the ‘fileio’ directory loving in the beginning finish

    distribution of the textbook.

    7. Each subject (1 through 5 with irrelative arguments) succeed be tested.

    Expert Confutation

     

    Here is the C program that copies full from peculiar finish to intention finish:

    #include <stdio.h>

    #include <stdlib.h>

    int ocean()

    {

    FILE *fptr1, *fptr2;

    char finishname[100], c;

    printf(“Enter the finishname to unconcealed ce lection n”);

    scanf(“%s”, finishname);

    fptr1 = fopen(filename, “r”);

    if (fptr1 == NULL)

    {

    printf(“Cannot unconcealed finish %s n”, finishname);

    exit(0);

    }

    printf(“Enter the finishname to unconcealed ce agreement n”);

    scanf(“%s”, finishname);

    fptr2 = fopen(filename, “w”);

    if (fptr2 == NULL)

    {

    printf(“Cannot unconcealed finish %s n”, finishname);

    exit(0);

    }

    c = fgetc(fptr1);

    while (c != EOF)

    {

    fputc(c, fptr2);

    c = fgetc(fptr1);

    }

    printf(“nSpace copied to %s”, finishname);

    fclose(fptr1);

    fclose(fptr2);

    return 0;

    }