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
Your instructor has asked you to perform some research regarding a computer OS capability of distinguishing spoken words. What i
tekilochka [14]
It’s A !!!!!!!!! Just did it
3 0
3 years ago
Aapke question about computer keyboard​
Lapatulllka [165]

Explanation:

A computer keyboard is an input device that allows a person to enter letters, numbers, and other symbols (these are called characters in a keyboard) into a computer. It is one of the most used input devices for computers. Using a keyboard to enter lots of data is called typing

8 0
3 years ago
What happens when i expose a disk to magnetic fields?​
lesya692 [45]

Answer:

When exposed to the powerful magnetic field of a degausser, the magnetic data on a tape or hard disk is neutralized, or erased. Degaussing is the guaranteed form of hard drive erasure, as such; it serves as the standard method of data destruction.

Explanation:

3 0
3 years ago
Differentiate between Scope and Linkage
Lera25 [3.4K]

Answer: The difference between the scope and linkage is as follows:-

  • Scope of the variable is defined as the variable view from different program parts whereas the linkage is described as the link that is made between the variable and the declaration function having the common name.
  • Scope of variable describes about the existing time of the variable in the program whereas linkage is defined for the name of variable present in the program is available at all time .

6 0
3 years ago
How does the technology work
Ivan

Answer:  it does – or perhaps appears to do – in the world.

Explanation:

sorry if am not right have a nice day lol

6 0
3 years ago
Read 2 more answers
Other questions:
  • You are to create a program using Python that asks the user for a nonnegative number, then computes the mean and variance using
    15·1 answer
  • Drag each storage device to its category.
    7·1 answer
  • Is anyone really good at immerse 2 learn??
    9·1 answer
  • What is the purpose of an internet protocol address (ip address)? it specifies whether a computer is using a broadband network o
    10·1 answer
  • What does digital mean, in the term of computer science.
    11·1 answer
  • What is it called when you remove some information from a file or remove a file from the disk ? A) save b) delete c) edit d) rem
    5·1 answer
  • [1] Our son has started playing organized T-ball, a beginner’s version of baseball. [2] “Organized” is what parents call it, any
    9·2 answers
  • CSCU EXAM TEST FINAL1-A software or hardware that checks information coming from the Internet and depending on the applied confi
    6·1 answer
  • What is the maximum number of extended partitions can you have on a hard drive?
    14·1 answer
  • A(n) ____ is a web-based repository of information that anyone can access, contribute to, or modify.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!