file:///C/Users/Hamst/Desktop/Lab6Doc.txt file:///C/Users/Hamst/Desktop/Lab6Doc.txt[4/4/2021 10:23:18 PM] For Lab 6: XXXXXXXXXXStudy the relationships between the given lab6.c, lab6_utils.h, and...

1 answer below »
Everything you need is in the zip file, the 2 C files have commented sections with "TODO" these are the areas where you will type the code and implement what it asks. Please do not modify any existing code as that is what is provided to us.


file:///C/Users/Hamst/Desktop/Lab6Doc.txt file:///C/Users/Hamst/Desktop/Lab6Doc.txt[4/4/2021 10:23:18 PM] For Lab 6: 0) Study the relationships between the given lab6.c, lab6_utils.h, and lab6_utils.c source code files. Notice that the function definitions from Lab5 char_is_punctuation() remove_char_at_str_pos() have been moved into lab6_utils.c along with their prototypes specified in the header file called lab6_utils.h Going back to lab6.c, notice the insertion near the other #include statements: #include "lab6_utils.h" I will walk through the creation of a makefile that builds the source code lab6.c and lab6_utils.c and lab6_utils.h into an executable binary called lab6 that can be run in the same manner that lab5 was with command-line arguments. $ ./lab6 input2.txt output2.txt Now to compile, you will simply run $ make To remove binaries, run $ make clean 1) Note the presence of the new function prototype in lab6_utils.h int copy_file(const char *src_file_name, const char *dest_file_name); where number of bytes copied is to be returned. TODO: Implement this function copy_file() in lab6_utils.c to open ( using fopen() ) the file with name src_file_name in "r" mode, open a new file in "w" mode with name dest_file_name using either fgetc() and fputc() OR fread() and fwrite(), and keep track of number of bytes read to be returned. HINT: See the example in https://www.geeksforgeeks.org/c-program-copy-contents-one-file-another-file/ (NOTE: Later, we will see that system functions can use 'cp' within C code.) BE SURE TO CALL fclose() on both file pointers before the return of this function. 2) Assume the use of command line arguments where argv[1] is either input1.txt or input2.txt and argv[2] is correspondingly either output1.txt or output2.txt. TODO: Dynamically allocate to char* byte_contents; a char array of length (file_length+1). Set the last cell to have value '\0'. 3) Note the new function prototype in lab6_utils.h void copy_file_to_str(const char* src_file_name, char* dest_str); TODO: implement copy_file_to_str() in lab6_utils.c 3) TODO: Use the functions from Lab5 to modify the string byte_contents to remove all of the punctuation. HINT: The while loop from Lab5 is commented out for your reference. 4) TODO: Using the copied and modified contents of byte_contents, write into the file with name argv[2] using a while loop in conjunction with fputc(); or just use fputs(). If you are using fputc() in a while loop, in place of the final '\0' of byte_contents, have EOF written as the last byte in file_to_modify. As before, use the 'diff' shell command to compare e.g., output2.txt with expected2.txt Local Disk file:///C/Users/Hamst/Desktop/Lab6Doc.txt
Answered 3 days AfterApr 05, 2021

Answer To: file:///C/Users/Hamst/Desktop/Lab6Doc.txt file:///C/Users/Hamst/Desktop/Lab6Doc.txt[4/4/2021...

Kamal answered on Apr 08 2021
142 Votes
lab6.c
/* LAB 6
* Name:
*************************************
To be filled out by instructor
Grade: (Out of 20)
    Compiles:
    Runtime:
    Other Comments
*************************************
*/
/* Lab6: This is an extension of the Lab 5 w
ork to make use of
    1) Multiple files and a makefile
    2) Use of FILE* pointer functions such as fread(), fgetc(), fwrite(), fputc(), fseek().
    ** With command-line arguments, run as
    For Lab 6:
    0) Study the relationships between the given lab6.c, lab6_utils.h, and lab6_utils.c source code files.
        Notice that the function definitions from Lab5
            char_is_punctuation()
            remove_char_at_str_pos()
        have been moved into lab6_utils.c
        along with their prototypes specified in the header file called lab6_utils.h
     Going back to lab6.c, notice the insertion near the other #include statements:
            #include "lab6_utils.h"
     I will walk through the creation of a makefile that builds the source code lab6.c and lab6_utils.c and lab6_utils.h
        into an executable binary called lab6 that can be run
        in the same manner that lab5 was with command-line arguments.
         $ ./lab6 input2.txt output2.txt
     Now to compile, you will simply run
        $ make
     To remove binaries, run
        $ make clean
        
    1) Note the presence of the new function prototype in lab6_utils.h
        int copy_file(const char *src_file_name, const char *dest_file_name);
     where number of bytes copied is to be returned.
     TODO: Implement this function copy_file() in lab6_utils.c
        to open ( using fopen() ) the file with name src_file_name in "r" mode,
        open a new file in "w" mode with name dest_file_name
        using either fgetc() and fputc() OR fread() and fwrite(),
        and keep track of number of bytes read to be returned.
        HINT: See the example in
            https://www.geeksforgeeks.org/c-program-copy-contents-one-file-another-file/
        (NOTE: Later, we will see that system functions can use 'cp' within C code.)
        BE SURE TO CALL fclose() on both file pointers before the return of this function.
    2) Assume the use of command line arguments where argv[1] is either input1.txt or input2.txt
        and argv[2] is correspondingly either output1.txt or output2.txt.
     TODO: Dynamically allocate to
            char* byte_contents;
         a char array of length (file_length+1).
         Set the last cell to have value '\0'.
    3) Note the new function prototype in lab6_utils.h
            void copy_file_to_str(const char* src_file_name, char* dest_str);
     TODO: implement copy_file_to_str() in lab6_utils.c
    3) TODO: Use the functions from Lab5 to modify the string byte_contents to remove all of the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here