1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marina86 [1]
3 years ago
6

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

ly the same as s2
Computers and Technology
1 answer:
anyanavicka [17]3 years ago
3 0

Answer:

Explanation:

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#define MAX 1024

int total = 0 ;

int n1, n2;

char s1, s2;

FILE fp;

int readf(FILE fp)

{

 if((fp=fopen("strings.txt", "r"))==NULL) {

   printf("ERROR: can’t open string.txt!\n");

   return 0;

 }

 s1=(char)malloc(sizeof(char)MAX);

 if(s1==NULL) {

   printf("ERROR: Out of memory!\n");

   return 1;

 }

 s2=(char)malloc(sizeof(char)MAX);

 if(s1==NULL) {

   printf("ERROR: Out of memory!\n");

   return 1;

 }

 /* read s1 s2 from the file */

 s1=fgets(s1, MAX, fp);

 s2=fgets(s2, MAX, fp);

 n1=strlen(s1); /* length of s1 */

 n2=strlen(s2)-1; /* length of s2 */

 if(s1==NULL || s2==NULL || n1<n2) /* when error exit */

   return 1;

}

int num_substring(void)

{

 int i, j, k;

 int count;

 for(i=0; i<=(n1-n2); i++) {

   count=0;

   for(j=i, k=0; k<n2; j++, k++){ /* search for the next string of size of n2 */

   if((s1+j)!=(s2+k)) {

     break;

   }

   else

     count++;

   if(count==n2)

     total++; /* find a substring in this step */

   }

 }

 return total;

}

int main(int argc, char argv[])

{

 int count;

 readf(fp);

 count=num_substring();

 printf("The number of substrings is: %d\n", count);

 return 1;

}

You might be interested in
"A Windows laptop is being used by a teacher in an outdoor (but protected by an overhang) setting. What setting would ensure tha
iragen [17]

1.Click the battery btn and go into power option.

2.Go into "When to turn off display" from left side bar menu.

3.And select for brightness drop down as never dims the display.

This will make the display turn on, no matter if the PC keyboard btn or mouse hower is clicked or not.

4 0
3 years ago
Read the section, "Junior Year." Why would someone chose to complete an apprenticeship after high school? How many occupations c
Tamiku [17]

An apprenticeship prepares you for a career through a structured program of on-the-job learning with classroom instruction, while you work and earn a salary. The programs can last from one to six years and you can choose careers in areas such as telecommunications, health care, computing, business support and the arts. The most common apprenticeships are in construction and manufacturing. If you like to work with your hands and your mind, you might want to consider an apprenticeship after high school. More than 850 occupations can be learned on the job through an apprenticeship.

7 0
3 years ago
Read 2 more answers
Who is your favorite<br><br> A. Jacksepticeye<br><br> B. SSSniperwolf<br><br> C. Markiplier
Korvikt [17]

Answer:

C

Explanation:

he be looking better than cashmoney

8 0
2 years ago
Read 2 more answers
What is the only language a microprocessor can process directly but most programmers almost never write programs in this code?
Phantasy [73]
Assembly language, a.k.a. machine language.
6 0
3 years ago
________ is a wireless protocol designed for transmitting data over short distances, replacing cables. ipv6 ipv4 paas bluetooth
KIM [24]
Wifi is a wireless protocol designed
3 0
3 years ago
Other questions:
  • How do you jumpstart a car in the middle of nowhere??? Explain using 2 paragraphs.
    14·2 answers
  • The process of providing and denying access to objects is called:
    5·1 answer
  • When solving for K, when cell potential is known, what is one of the first steps to follow?
    8·1 answer
  • is a shell program in Windows that holds individual utilities called snap-ins, designed for administration and troubleshooting.
    11·1 answer
  • How are people using lying today? What are the types of lying? Describe each type.
    7·1 answer
  • Jenny's needs to buy a computer to create word documents, make presentations, listen to music, and watch movies and videos. Whic
    13·1 answer
  • Guys help—How do you start a conversation with someone on brainly if that is a thing?
    6·1 answer
  • Which of the following are NOT possible using the RANDOM(a, b) and DISPLAY(expression) abstractions?
    10·1 answer
  • A two-dimensional array has been defined to hold the quantity of each of 5 different healthy snack products sold in a tuckshop d
    10·1 answer
  • A salesman has been traveling to different businesses all day to give a sales presentation. Each time, he was starts up his lapt
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!