Question: Problem Statement You will be given an NxN matrix with strings in each cell, as well as a text file containing a large number of

Problem Statement
You will be given an NxN matrix with strings in each cell, as well as a text file containing a large number of strings. Your task is to only write a POSIX compliant C program that finds the number of times each string in the matrix occurs in the given text file as efficiently as possible.
Catch: Each string in the matrix (except the one in the very first cell) will be encoded with a Caesar Cipher, and must be decoded using a key before its occurrences in the file can be counted.
The key to decode the strings can be obtained by communicating with another process, the helper process, using a message queue.
The helper process will already be running and ready to communicate with your program. You dont have to write the helper process.
All the strings belonging to a specific right diagonal of the matrix will have the same key,which may be received by sending the sum of the occurrences of all the strings in theprevious diagonal to the helper process.
The matrix will be present in a shared memory that your program will have to bconnect to.More details for the same are given below.
The Input: Your program will receive exactly one command line argument, which will be a numberwith at most two digits. This number will be used to access the files your program needs to read,i.e., the input file and the words file. These files will be named as input[t].txt and words[t].txt,where t is the command line argument received (The square braces are not part of the name). Forinstance, if the command line argument received is 3, these files will be named input3.txt andwords3.txt.
The first of these, the input file, will be present in the same directory where your program will berun. It will have four lines of text. Each line will contain a single integer, in the following format:
Size of the matrix (N)
Maximum length of a word in the words file
The key for connecting to the shared memory containing the NxN matrix
The key for connecting to the message queue to communicate with the helper
A sample input file may look as so: input1.txt
150
213
389383
430886
The Matrix: This will be an NxN matrix stored in the shared memory whose key is given in theinput file described above.You may connect to the same via the shmget function. Considering thatthe shared memory is a 2D array of strings you may refer to the function signatures provided belowto access the shared memory correctly. Your program is allowed to make changes to the matrix ifneeded.
Function Signatures to work with the 3D matrix (third dimension is for the string, which is a
character array in C)
char (*shmptr)[N][stringSize];
shmget(key_t key, size_t sizeof(char[N][N][stringSize]), int shmflg)
shmat(shmId, NULL, 0);
Here, N is the side length of the matrix, stringSize refers to the maximum string length, as given inthe input file.
With this signature, after connecting to the shared memory, shmptr[i][j] will address the wordpresent at the ith row and jth column of the matrix (0<= i, j < N)
The Text File: There will be a text file named words[t].txt present in the same directory as the oneyour code is run from, containing a large number of strings separated by spaces. This is the filefrom which you must count the number of occurrences of specific words, as given in the matrix.Note that each word, both in this file and in the matrix, will contain only lowercase Englishcharacters.
The Helper Process: A helper process will automatically be started when your code is executed.Your program can communicate with it using a message queue, which can be connected to usingthe key provided in the input file described above. You will be required to send one message to itfor each right diagonal of the matrix. The ith message must correspond to the sum of the numberof occurrences of each word in the ith right diagonal of the matrix. If thecorrect sum is input, the helper process will reply on the same message queue with an integerrepresenting the key for the Caesar Cipher for the next right diagonal of the matrix. This key willrange from 0 to 10^5. Once the final message (i.e., the number of occurrences of the word present
in the last cell of the matrix) is sent, the execution will be considered complete.The Helper replies to the last value with 0 if it is correct, and -1 if it isnt. After receiving this
final value, ensure that your process follows the guidelines for cleanup activities needed for theshared memory and message queue as mentioned below, and exit as well.
The Helper will listen to messages of mtype 1 from your program, and will send responses withmtype 2. For only the first diagonal, please send the answer as -300.
This needs to be done using the C language. Your solution should be POSIX
compliant and run on an Ubuntu System (>=22.04). You are allowed to use either multiple processes or threads or both for efficiency
please dont use chatgpt or some other ai tools for solving this question

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!