Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use a const char for this: const char* my messages [4]fEnglish: Hello!, French: Bonjour!, Spanish: Hola!, German: Guten Tag! Note that you must use a
Use a const char for this: const char* my messages [4]f"English: Hello!", "French: Bonjour!", "Spanish: Hola!", "German: Guten Tag!" Note that you must use a character arrays just as shown here 4. Modify the program to define a pthread function called printMessage that is sent a single integer parameter, index (wrapped in a void*). The function prints the message stored in the location index of the array my messages. You will need to use an explicit type cast in the function to get the index value from the void* parameter. 5. Modify the main function to create as many threads as there are messages in the global array, instruct each thread to execute the function printMessage and pass each thread the index of a different location in the array as a parameter (this code will go between the comment that says "TODO: Modify according to assignment requirements" and the "if (rc)" check). So, each thread will essentially execute the same function, but will print a different message based on the parameter it receives. 6. Compile your program and run it several times. Note that the output of your program is likely to look garbled and may not always show the
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started