Question: Problem Overview: You need to write a POSIX - compliant C program that: Reads an NxN matrix of strings from shared memory. Decodes all strings

Problem Overview:
You need to write a POSIX-compliant C program that:
Reads an NxN matrix of strings from shared memory.
Decodes all strings (except the one in the very first cell) using a Caesar Cipher.
Counts how many times each string in the matrix occurs in a text file (words[t].txt).
Caesar Cipher keys are obtained via a message queue by sending sums of string occurrences from the matrixs diagonals to a helper process. The key ranges from 0 to 10^5
The matrix and text file details are provided via an input file (input[t].txt).
You will communicate with both shared memory and a message queue.
Input Files:
Your program will receive one command-line argument: a number t (maximum 2 digits, i.e.,<=99). This number determines the names of two files:
Text file: words[t].txt contains a large number of strings (separated by spaces).
Input file: input[t].txt provides the following:
Size of the matrix (N)
Maximum length of a word in the words file
Key for connecting to the shared memory (to access the matrix)
Key for connecting to the message queue (to communicate with the helper process)
Example input[t].txt:
50
13
89383
30886
Matrix in Shared Memory:
The NxN matrix of strings is stored in shared memory, and you must connect to it using the key from the input file.
The matrix is a 2D array of strings (each string is a character array).
Connect to the shared memory using the following function signatures:
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, and stringSize refers to the maximum word length given in the input file.
Once connected, you can access matrix elements as shmptr[i][j](where 0<= i, j < N).
Caesar Cipher:
All strings in the matrix (except the one in the very first cell, i.e., shmptr[0][0]) are encoded with a Caesar Cipher.
The same key is used to decode all strings in a given right diagonal of the matrix.
The key for the next diagonal is obtained by sending the sum of the occurrences of all the strings in the previous diagonal to a helper process via a message queue.
The helper process (already running) will respond with an integer representing the Caesar Cipher key for the next diagonal. The key will be between 0 and 10^5
Once you have the key, use it to decode the strings before counting their occurrences in the text file.
Counting Occurrences:
The program should count how many times each decoded string from the matrix appears exactly in the text file words[t].txt.
Note: Strings that appear as substrings in other words should not be counted. For example, if the word abc is in the matrix, it should not be counted within a word like hbabcp.
A function wordFindFileOpenFunction should be implemented that:
Opens the text file.
Checks if each word is found.
Returns 2 if a word is found and 0 if its not.
Message Queue and Helper Process:
Your program will communicate with the helper process via a message queue, using the key from the input file.
Message Protocol:
Your program sends a message of type 1 with the sum of occurrences of words in each diagonal of the matrix.
The helper process will respond with a message of type 2, which contains the Caesar Cipher key for the next diagonal.
For each right diagonal (there are 2N -1 right diagonals in an NxN matrix), send the sum of occurrences and receive the key for the next diagonal.
Once all diagonals are processed, the helper process will:
Send 0 if the final sum is correct.
Send -1 if theres an error (e.g., an incorrect sum), and the process will exit early.
Diagonals and Key Communication:
A matrix has 2N -1 right diagonals. The right diagonal starts from any cell in the first row or last column and goes diagonally downwards.
For example, in a 3x3 matrix:
Diagonal 1: (0,0)
Diagonal 2: (0,1) and (1,0)
Diagonal 3: (0,2),(1,1), and (2,0)
Diagonal 4: (1,2) and (2,1)
Diagonal 5: (2,2)
For each diagonal, count the number of occurrences of its strings, send the sum to the helper process, and receive the Caesar Cipher key for the next diagonal.
Word Matching:
Both the matrix and words[t].txt contain only lowercase English letters.
Ensure that only exact matches are counted (substrings should not be included).
Cleanup:
When done, detach from the shared memory and message queue.
Do not delete the shared memory or message queue (shmctl and msgctl are not to be used for deletion). Please dont use any ChatGPT or any other AI tools

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!