Question: Given two character strings s1 and s2. Write a Pthread program to find out the number of substrings, in string s1, that is exactly the

Given two character strings s1 and s2. Write a Pthread program to find out the number of substrings, in string s1, that is exactly the same as s2. For example, suppose number_substring(s1, s2) implements the function, then number_substring(abcdab, ab) = 2, number_substring(aaa, a) = 3, number_substring(abac, bc) = 0. The size of s1 and s2 (n1 and n2) as well as their data are input by users. Assume that n1 mod NUM_T HREADS = 0 and n2

The following is a sequential solution of the problem. read_f() reads the two strings from a file named string.txt and num_substring() calculates the number of substrings.

Given two character strings s1 and s2. Write a Pthread program to

find out the number of substrings, in string s1, that is exactly

Write a parallel program using Pthread based on this sequential solution

#include #include #include #define MAX 1024 int total = 0 int n,n2 char s1,s2 FILE sfp; int readf (FILE fp) if(( fp-fopen ( " strings . txt", "r"))=NULL) { printf ( ERROR: can t open string.txt! " return 0 s1=(char *)malloc (sizeof(char ) *MAX); if(s1=NULL ) { printf ERROR: Out of memory!" return-1 s2-(charmalloc (sizeof (char)MAX); if(s1=NULL) { printf( ERROR: Out of memory" return-1 sread s1 s2 from the files/ s1-fgets (s, MAX, fp); s2-fgets (s2, MAX fp) n1=strlen(s1); /* length of s1*/ n2-strlen (s2)-1 length of s2/ if(s1=-NULL II s2-NULL 11 n1 #define MAX 1024 int total = 0 int n,n2 char s1,s2 FILE sfp; int readf (FILE fp) if(( fp-fopen ( " strings . txt", "r"))=NULL) { printf ( ERROR: can t open string.txt! " return 0 s1=(char *)malloc (sizeof(char ) *MAX); if(s1=NULL ) { printf ERROR: Out of memory!" return-1 s2-(charmalloc (sizeof (char)MAX); if(s1=NULL) { printf( ERROR: Out of memory" return-1 sread s1 s2 from the files/ s1-fgets (s, MAX, fp); s2-fgets (s2, MAX fp) n1=strlen(s1); /* length of s1*/ n2-strlen (s2)-1 length of s2/ if(s1=-NULL II s2-NULL 11 n1

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!