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
Bcghxdfghncfghndfgxdfgjfjgktyerdgftguj
IgorLugansk [536]

Answer:

Okay

Explanation:

4 0
3 years ago
Read 2 more answers
1. What are the advantages and disadvantages of technology in communication?
Gennadij [26K]

Answer:

ADVANTAGES:

First, the evolution of technology is beneficial to humans for several reasons. At the medical level, technology can help treat more sick people and consequently save many lives and combat very harmful viruses and bacteria.

2-Technology has also increased the productivity of almost every industry in the world. Thanks to technology, we can even pay with bitcoins instead of using banks

DISADVANTAGES:

1-Lack of Privacy. You might think that a quick text or IM offers more privacy than a telephone call in a crowded room. ...

2-Distraction from Real Life. ...

3-Potential for Misunderstanding. ...

4-Decline of Grammar and Spelling...

5- Near people are far and far people are near through communication technology. we have no time to sit with our relatives but constantly communicate far away people . I think this is biggest <em>disadvantage </em>

Explanation:

7 0
3 years ago
Read 2 more answers
A(n) ___________ allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as
nasty-shy [4]

Answer:

A(n) videoconference allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as well as share documents, data, computer displays, and whiteboards.

6 0
2 years ago
When is the redo log buffer written to the redo log file?
natka813 [3]

Answer: B)The redo log buffer becomes one-third full.

Explanation:Redo log buffer is the type of buffer file that is present for storing the changes that have been done in data. Database changes are the made goes in the records of the redo entries.the change of the buffer to the redo files is done when the buffer contains change records which are full till the one-third section, thus conversion takes place from the redo buffer to the redo files.

5 0
2 years ago
Why was unicode invented?
Julli [10]
Unicode was invented to create a "universal text", or a language framework that any computer or device could understand. 


5 0
3 years ago
Other questions:
  • For local travel addresses and street names should be
    14·1 answer
  • You can encrypt individual files, but microsoft recommends encrypting at what level?
    9·1 answer
  • What kind of information B2B SaaS companies wish to know about their competition, apart from information about their competitors
    15·1 answer
  • Can someone that been helping me answer one more question for please and thx
    13·1 answer
  • A technician has been asked to upgrade a processor and needs to do some research. The computer is just a couple of years old. Wh
    13·1 answer
  • Not every organization integrates with the Internet, but all use some or most of the technology that gave rise to it.
    15·1 answer
  • The owner of a candle shop has asked for your help. The shop sells three types of candles as shown below:
    9·1 answer
  • What’s cloud-based LinkedIn automation?
    14·1 answer
  • You have two identical print devices that are set up in a work room. Currently, the Windows print server has two printers config
    13·1 answer
  • Is a device used to test the network connection.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!