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
he attributes for an iframe are controlled by CSS. One of the iframe controls is "seamless." This means it _____. will blend the
Aleks [24]

Answer:

A. Will blend the iframe to look like the surrounding page

3 0
2 years ago
Which port-authentication network access control standard forces devices to go through a full authentication, authorization, and
DiKsa [7]

802.1X is the port-authentication network access control standard that forces devices to go through a full authentication, authorization, and accounting (AAA) process to get anywhere past the interface on a gateway system. This standard is defined by the IEEE and defines a client and server-based access controls.In a wireless LAN with 802.1X, a user (known as the supplicant) requests access to an access point (known as the authenticator).

5 0
3 years ago
Which best describes obliteration in a forged document?
Drupady [299]
The answer is B bc obliteration is related to covering the document
4 0
3 years ago
Effective communication skills are a desirable workplace skill
OLga [1]
Yes. If there is no effective communication in the workplace then nothing is going to be done.
4 0
3 years ago
Write a recursive function that returns 1 if an array of size n is in sorted order and 0 otherwise. Note: If array a stores 3, 6
galina1969 [7]

Answer:

The function in C++ is as follows:

int isSorted(int ar[], int n){

if (n == 1 || n == 0){

 return 1;}

if (ar[n - 1] < ar[n - 2]){

 return 0;}

return isSorted(ar, n - 1);}

Explanation:

This defines the function

int isSorted(int ar[], int n){

This represents the base case; n = 1 or 0 will return 1 (i.e. the array is sorted)

if (n == 1 || n == 0){

 return 1;}

This checks if the current element is less than the previous array element; If yes, the array is not sorted

if (ar[n - 1] < ar[n - 2]){

 return 0;}

This calls the function, recursively

return isSorted(ar, n - 1);

}

6 0
3 years ago
Other questions:
  • 9. The best way to insert an existing Excel chart into a document is to A. use the Object command. B. click the Insert tab and c
    6·2 answers
  • What type of installation should you perform if you want to install a 64-bit version of Windows on a computer that already has a
    8·1 answer
  • Which one of these tasks best describes the process of localization?
    12·1 answer
  • What do you call the process of translating statements written by a developer? What is the result of this process?
    6·1 answer
  • Design and implement an application that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals. Sto
    9·1 answer
  • Which of these networks is primarily for posting and viewing photos?
    8·2 answers
  • 9.18 LAB: Exact change - methods Write a program with total change amount as an integer input that outputs the change using the
    11·1 answer
  • WILL MARK CORRECT ANSWER AS BRAINLIEST PLSSSS HELP!
    13·2 answers
  • How to create a network of relevant prospects?
    5·1 answer
  • Who is tim berners-lee
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!