Due: November 8, 2019
Please put the answers to these two questions in a text file called linux.txt or a PDF file called linux.pdf.
First, read in a file of no more than 1000 words (called a dictionary), and store them in a list. This is to be a list of character pointers, each pointing to a word. You will have to use malloc(3), which allocates space dynamically. Each line, including the last, will be ended with a newline, and no line will be over 1024 characters.
Then, read a second file. This file is also a list of words. Search your list for each word, and for each word print the number of words checked before you either get a match or find it is not in the list. For letters, the case must match (so “N” does not match “n”). Also, after you have finished searching for the words, print the average number of words checked.
The two files are given as command-line arguments to your program. The first argument is the dictionary, and the second is the list of words to be found.
To turn in: Put this program into a file called lookup.c; turn it in as directed below.
The next step is to load a predefined pattern onto the board for the game. The predefined pattern is in a file. That file contains rows of “X”s and “O”s (the characters “X” and “O”). The “X” corresponds to a populated cell and the “O” to an unpopulated one. Each line in that file should have the same number of columns. Your program is to read the file, load the configuration into memory, and print it out, properly framed by the board, and stop.
Your program will take the file with the predetermined pattern as its only argument. It is to print out the board. Note your program will have to count the rows and columns as these will not be given. Report any errors such as a line too long or too short.
As an example, the inmput file
XOXXOOXOX OOOXXXOOO OXOXOXOXO XOXOXOXOXdefines a board of 4 rows and 9 columns. It is a valid board. But the board
OXOXO XXXX OOOOOOis not valid as the rows are of different lengths, and the board
XOXXOOXOX OOOXYXOOO OXOXOXOXO XOXYXOXOXis not valid because there is a character other than X, O, and newline in the file (specifically, two instances of “Y”). Your program is to report errors in these cases, and then terminate.
The board dimensions will never be more than 100 rows and 100 columns.
To turn in: Put this program into a file called life2.c; turn it in as directed below. If you want to submit two files, that is, have this in a separate file, call the main one life2.c and the other file(s) initn.c, where n is a single digit (for example, init0.c). Turn it in as described below.
To turn in: Fix the bug and say what you did in a comment at the beginning of the file. Turn in the fixed file as described below.
To turn in: Put this program into a file called lookups.c; turn it in as described below.
For this assignment, you are to create a tar(1) archive and a Makefile.
The Makefile is to have 3 or 4 targets: lookup, life2, revfile, and (if you do the extra credit) lookups. So, when I type make lookup, the Makefile will execute the command to compile your lookup.c program, and save the executable as lookup.
Put the answers to the Linux questions (in a text or PDF file), the Makefile and the programs you wrote into a directory called hw3-ans. Next, create a tar archive:
tar cvf hw3-ans.tar hw3-ansor whatever files you wish to submit. Then submit the tar archive to Canvas.
ECS 36A, Programming and Problem Solving
Version of October 30, 2019 at 8:18PM
|You can also obtain a PDF version of this.