Question: Would someone please parallelise the following method using 4 threads in OMP. //Text -> Morse code conversion void encrypt( FILE *outputfile, char *str, size_t len

Would someone please parallelise the following method using 4 threads in OMP.

//Text -> Morse code conversion void encrypt( FILE *outputfile, char *str, size_t len ) { unsigned char j, badc; size_t i; //Read characters from input file for ( i = 0; i < len; i++ ) { badc = 1; //Iterate through pseudo-hash, looking for matches for ( j = 0; j < SUPPORTED_CHARACTERS && badc; j++ ) { if ( tolower( str[i] ) == morse[j][0][0] ) { if ( ( str[i] == ' ' || str[i] == ' ' ) && flags & FLAG_NOPROSIGNS ) { badc = 0; continue; } //If next character is space, do not add additional one fprintf( outputfile, "%s%s", morse[j][1], ( i + 1 < len ) ? ( ( str[i + 1] == ' ' ) ? "" : " " ) : "" ); badc = 0; } } //If no matches were found, throw a warning if ( badc ) fprintf( stderr, "cmorse: unsupported character (ASCII only) - %c (0x%x) - c%ld ", str[i], str[i], (long) i ); } } 

This method converts a text file into morse code where `*outputfile` is the output file, `char *str` is the input string of words to be converted and `size_t len` is the length of `char *str`. The `morse`is a char containing all the values of conversions like this:

const char morse[SUPPORTED_CHARACTERS][2][8] =

{

{" ", " "},

{"e", "."},

{"t", "-"},

{"a", ".-"},

{"o", "---"},

{"i", ".."},

{"n", "-."},

{"s", "..."},

{"h", "...."},

{"r", ".-."},

{"d", "-.."},

{"l", ".-.."},

{"c", "-.-."},

{"u", "..-"},

{"m", "--"},

{"w", ".--"},

{"f", "..-."},

{"g", "--."},

{"y", "-.--"},

{"p", ".--."},

{"b", "-..."},

{"v", "...-"},

{"k", "-.-"},

{"j", ".---"},

{"x", "-..-"},

{"q", "--.-"},

{"z", "--.."},

{"0", "-----"},

{"1", ".----"},

{"2", "..---"},

{"3", "...--"},

{"4", "....-"},

{"5", "....."},

{"6", "-...."},

{"7", "--..."},

{"8", "---.."},

{"9", "----."},

{".", ".-.-.-"},

{",", "--..--"},

{":", "---..."},

{";", "-.-.-."},

{"?", "..--.."},

{"\'", ".----."},

{"!", "-.-.--"},

{"+", ".-.-."},

{"-", "-....-"},

{"/", "-..-."},

{"(", "-.--."},

{")", "-.--.-"},

{"\"", ".-..-."},

{"@", ".--.-."},

{"$", "...-..-"},

{"=", "-...-"},

{"&", ".-..."},

{"_", "..--.-"},

//Prosigns (in fact, unsure how to implement correctly)

{" ", ".-.-" },

{" ", "" } //Carriage return is ignored since it doubled line spacing

};

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!