Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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<2><2>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions