Question: help with code Overview This week, you will gain some experience with arrays, using loops to do the following: - declaring and initializing arrays (




Overview This week, you will gain some experience with arrays, using loops to do the following: - declaring and initializing arrays ( 2 2-D array) - filling up the array (the text) using redirection from a file - printing out the values in an array (printing out the text) Background Information In lecture, you have learned that strings are character arrays that are null terminated. When printing a string (character array), use the " s " format specifier with the print f() statement. When reading in a string from the keyboard, scanf() can be used with the " 8s" format specifier as well, but you leamed that scanf () only reads in characters up to a space, tab, or newline character. As you also leamed in lecture, there are other options for printing and writing out strings besides printf () and scanf () , some of which come from the string.h library file, and some from stdio.h library file. For this lab, you will use a function other than scanf () to read in text from a file and save it in an array. There are many different ways to read in text from a file. You will want to choose one that reads the entire line up to the newline character (we talked about one in lecture, you can refer to the lecture slides for a hint on which one). Lab Assignment For this week's lab assignment, you will write a program, called lab6.c. Your program will read in text from the given file poe-raven.txt using rediraction and save the text in an array. Storing multiple lines of text to an array requires a 2-D array - the first dimension refers to the number of rows (the number of lines) and the second dimension refers to the number of columns (the number of characters) of the longest iine. Using good programming practice, you can use a \#define statement or a const int variable to hold the values of the number of lines and the length of a line. Use 200 for the number of lines (MAX__INE) and 100 for the length of the lines (MaX_LINE_LEN) as the number of lines is less than 200 and 100 is plenty big enough for the longest line. By using a Idefine statement or a const int variable, you will not be hard-coding any loop conditions-it is typically preferred to not hard-code loop condition limits, especially when that value will be used in multiple locations in your code. The two ouputs of your program will be the text that you read in to the anay, and the total number of lines in the text. As you fill up your amay, you can keep track of the number of lines that are read each time a line is read in. Then you can use that value in the loop that will print the contents of the array back out. This program will be used for the following week's lab where you will add some more code to it to get more practice using string functions. Sample output is shown on the next page: Sample Output [14:09:18] chochriejoey15: [14] ./a.out a feather then be flutteredTill I scarcely more than mutcered, "other frienda have flown beforeon the morrow be vill leave ne, as my hopes bave flown before. " then the bird said, "Nevermore." startled at the stiliness broken by reply ao aptly apoken, "Doubtiess." "aid 1 , "what it utters is ity colly atock and store, "Wretch," I cried, "thy God hath lent thee-by these angels he hath sent thee Respite- respite and nepenthe, from thy memories of Lenore: Quaff, oh quaff this kind nepenthe and forget this lost Lenore!" Quoth the Raven, "Nevermore." "Prophet!" said I, "thing of evil! - prophet still, if bird or devili- Whether Tempter sent, or whether tempest tossed thee here ashore, Desolate yet all undaunted, on this desert land enchantedon this home by horror haunted- tell me truly, I imploreIs there- is there balm in Gilead? - tell me-tell me, I implore!" Quoth the Raven, "Nevermore." "Prophet:" said I, "thing of evil-prophet stil1, if bird or devil! By that Heaven that bends above us- by that God we both adoreTel1 this soul with sorrow laden if, within the distant Aidenn, It shall clasp a sainted maiden whom the angels name LenoreClasp a rare and radiant maiden whom the angels name Lenore." Quoth the Raven, "Nevermore." "Be that word our sign in parting, bird or fiend," I shrieked, upstarting- "Get thee back into the tempest and the Night's plutonian shore! Leave no black plume as a token of that lie thy soul hath spokent Leave my loneliness unbroken! - quit the bust above my door! Take thy beak from out my heart, and take thy form from off my door!" Quoth the Raven, "Nevermore." And the Raven, never flitting, still is siteing, still is siteing On the pallid bust of Pallas just above my chamber door: And his eyes have all the seeming of a demon's that is dreaning. And the lamplight o'er him streaming throws his shadow on the floor? And my soul from out that shadow that lies floating on the tloor Shall be lifted- nevermorel Reminder About Formatting and Comments - The top of your file should have a header comment, which should contain: Your name 0 Course and semester - Lab number - Brief description about what the program does - Any other helpful information that you think would be good to have. - Variables should be declared at the top of the main function, and should have meaningful names. - Always indent your code in a readable way. Some formatting examples may be found here: https://people.cs.clemson edu/-chochri/Assignments/Formatting Examples.pdf - Don't forget to use the -Wal1 flag when compiling, for example: gcc -Wal1 lab6 .c Turn In Work Show your ta that you completed the assignment. Then submit your 1ab6.c file to Gradescope
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
