Question: edit and write in c++ #include #include #include #define MAX_NUM_THREADS 8 char *messages[MAX_NUM_THREADS]; struct thread_data { int thread_id; char *message; }; struct thread_data thread_data_array[MAX_NUM_THREADS]; void

edit and write in c++

#include #include #include #define MAX_NUM_THREADS 8

char *messages[MAX_NUM_THREADS];

struct thread_data { int thread_id; char *message; };

struct thread_data thread_data_array[MAX_NUM_THREADS];

void *PrintHello(void *threadarg) { int taskid; char *hello_msg; struct thread_data *my_data;

sleep(1); my_data = (struct thread_data *) threadarg; taskid = my_data->thread_id; hello_msg = my_data->message; printf("Thread %d: %s ", taskid, hello_msg); pthread_exit(NULL); }

int main(int argc, char *argv[]) { pthread_t threads[MAX_NUM_THREADS]; int *taskids[MAX_NUM_THREADS]; int rc, t;

size_t malloc_size = 100;

for (int i = 0; i < 8; i++) { messages[i] = malloc(malloc_size * sizeof(char)); /* allocates 100 bytes */ printf("Enter messages:%d ",i+1); // as indicated in question input is taken from user scanf("%[^ ]%*c", messages[i]); // geting string until newline character is entered

//Then, with this %*c, it reads newline character and here used *indicates that this newline character is discarded } for(t=0;t

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 Databases Questions!