Microsoft Word - Lab2.docx CIS*2500 (Intermediate Programming) Lab #2 – Dynamic memory allocation Due date: End of Week 5, Saturday Feb 12th at 11:59PM EST (Submit to the GitLab repository)...

1 answer below »
I have lab work to be done in c programming.


Microsoft Word - Lab2.docx CIS*2500 (Intermediate Programming) Lab #2 – Dynamic memory allocation Due date: End of Week 5, Saturday Feb 12th at 11:59PM EST (Submit to the GitLab repository) Description Your program will take a text file as input that has x lines of a poem. The poem ends with a period. After the end of the input stage, the program will print how many lines and words are in the poem and how many words are on each line of the poem. The first line of output provides the total words and lines in the poem, and the second line is a space-delimited list of the number of words on each line of the poem provided. See Sample Input and Output for more details. Two sample input files named poem.txt and poem2.txt are given for convenience. Sample Input and Output 1 $ ./poetry poem.txt 15 words on 3 lines 7 5 3 Sample Input and Output 2 $ ./poetry poem2.txt 37 words on 6 lines 7 6 6 5 9 4 Sample Input and Output Explanation - The program is run with the name of the input file as a command-line argument - The program them indicates the total number of words in the poem, and the total number of lines inputted (15 and 3, respectively). This is the first of two lines of output. - The second line is a space-delimited list of the number of words on each line. In this case, the three lines of the poem has seven words on the first line, five words on the second line, and three words on the third line. - The program ends the space-delimited list with a newline. Constraints Input file: Lines of poetry • Contain no punctuation (except the period to indicate the end of the poem). • No word can be greater than 20 characters in length • No line can be greater than 100 characters in length • You must not use static allocation of arrays – they must be allocated dynamically. The number of input lines is unknown, so you must dynamically reallocate your array as the program runs. Output • The first line of output will have the following format x words on y lines where x is the number of words and y is the number of lines and there are single spaces (blank characters) between each number or word. If words or lines = 1 then words should be changed to word and lines to line, respectively. • The second line of output will have a format as shown in the above sample input / output scenario (basically number of words on each line separated by spaces). Program Structure • The program is to be named poetry.c. If you choose to use multiple files, then write your main function in a file called main.c, all your function prototypes and such in a header file called header.h, and all function definitions in a file called poetry.c • You must use a makefile to compile the code and to produce an executable called poetry. • DO NOT use global variables. • No debugging prints may appear during the execution of poetry when it is being graded. Other Rules • Your code must compile cleanly with no error or warning messages using -Wall and - std=c99 flags in gcc on the SOCS server • You must use realloc when resizing the array that holds the number of words per line. A small deduction will be applied if realloc is not used. • All work is to be done independently. If the TA deems that you have not done the coding independently then they will not grade the assignment. • Code that cannot be compiled with your makefile will not be graded. Your makefile should compile your code when the user inputs “make” into the command line. Submission Instructions • Ensure the most recent copy of your program is updated to your GitLab repository, with the following restrictions: o If you use a single file, then you must submit makefile and your program file called poetry.c o If you use multiple files, then you must submit makefile and your program files (main.c, header.h, poetry.c) o Your makefile should expect the main.c, header.h and poetry.c files to be located in the same directory as your makefile. • Recap on submission to Gitlab Step 1: Login to the school server and cd to the directory that you work on from the terminal application (or use the method that used to submit L1). Step 2: From the chosen directory, now type: git clone https://git.socs.uoguelph.ca/2500W22//L2.git At this point, you have a directory to work with on your account (or on your local system) Step 3: Do the work - (remember to) cd to the new directory - create the file that you are working on - after first save, type: git add filename ONLY ADD THE FILE ONCE!!! //do not do: git add . Loop every 20-30 minutes: git commit -am "write something here about what you just did" Once per day: git push // this is what stores local work back to the server. To learn more about Gitlab, go to this link on moodle https://moodle.socs.uoguelph.ca/course/view.php?id=169 Make and Makefiles Your makefile should look similar to the following (if you use a single file called poetry.c): CC=gcc CFLAGS=-Wall -std=c99 poetry: poetry.o $(CC) poetry.o -o poetry poetry.o : poetry.c $(CC) $(CFLAGS) -c poetry.c clean : rm poetry poetry.o Remember that there is a before lines starting with $(CC) and rm. Make may not work if there are spaces and not tabs. Note the use of macros CC and CFLAGS, used for readability and convenience. For more on makefile, read the tutorial found here: https://www.gnu.org/software/make/manual/html_node/Introduction.html#Introduction Now is the winter of our discontent Made glorious summer by this Sun of York. Throughout the afternoon I watched them there Snow-fairies falling falling from the sky Whirling fantastic in the misty air Contending fierce for space supremacy And they flew down a mightier force at night As though in heaven.
Answered 2 days AfterFeb 07, 2022

Answer To: Microsoft Word - Lab2.docx CIS*2500 (Intermediate Programming) Lab #2 – Dynamic memory allocation...

Vaibhav answered on Feb 10 2022
110 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here