Write a program that accepts a phrase of unspecified length onthe command line.
ID: 3608930 • Letter: W
Question
Write a program that accepts a phrase of unspecified length onthe command line. For example:
prompt% letterprint Operating Systems Class at Kent-State
The main() in this program has to create two threadsrunning functions (vow and cons). The threads should take turnsprinting the respective words of the phrase supplied on the commandline. The vow thread should print all the words that start with avowel and the cons thread should print all words starting with aconsonant. Note that the main thread (running main()) should notprint anything itself – the output should be supplied by thethreads that it creates. The order of words in the phrase shouldnot be
changed in the printout. Your program should work for any phraseof any reasonable length, not just the
one given in the example. The output of you rprogram shouldlooks similar to the following
prompt% letterprint Operating Systems Class at Kent-State
vow: Operating
cons: Systems
cons: Class
vow: at
cons: Kent-State
In this part you are not allowed to use synchronizationprimitives such as mutexes for thread coordination. You can usesched_yield() torelinquish control of the CPU.
Explanation / Answer
//Hope this will help you.. #define _MULTI_THREADED #include #include #include #define THREADS 2 int i=1,j,k,l; int argcG; char *argvG[1000]; void *threadfunc(void *parm) { int *num; num=(int*)parm; while(1) { if(i>=argcG) break; if(*num ==1) if(argvG[i][0]=='a' ||argvG[i][0]=='2'||argvG[i][0]=='i' ||argvG[i][0]=='o' ||argvG[i][0]=='u') { printf("%s ",argvG[i]); i++; continue; } if(*num ==2) if(!(argvG[i][0]=='a' ||argvG[i][0]=='2'||argvG[i][0]=='i' ||argvG[i][0]=='o' ||argvG[i][0]=='u')) { printf("%s ",argvG[i]); i++; continue; } sched_yield(); } return NULL; } int main(int argc, char *argv[]) { pthread_t threadid[THREADS]; int rc=0; int loop=0; int arr[2]={1,2}; argcG=argc; for(rc=0;rcRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.