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
tangare [24]
3 years ago
8

Write a complete C program that inputs a line of text and a search string from the keyboard. Using function strstr, locate the f

irst occurrence of the search string in the line of text, and assign the location to variable searchPtr of type char *. If the search string is found, print the remainder of the line of text beginning with the search string. Then, use strstr again to locate the next occurrence of the search string in the line of text. If a second occurrence is found, print the remainder of the line of text beginning with the second occurrence. Also, determine the total occurrences of the string in the lines of text. Print the results.

Computers and Technology
1 answer:
ddd [48]3 years ago
8 0

Answer:

Here is the C program:

#include <stdio.h>  // to use input output functions

#include <string.h>   // to manipulate strings

int main() //start of main() function body

{  char input_text[100];  // array to store the input text line

char search_string[50]; // char type array to store string to be searched

char *searchPtr;  

// char type pointer variable to search for search_string in input_text

printf("Input a text line \n");  // prompts user to enter a line

fgets(input_text,100,stdin);   // to get line of input text from user

printf("Input a string to search: ");  

//prompts user to enter string to be searched

scanf("%s", search_string);   //reads the value of search_string

//search for the search_string in input_text

searchPtr = strstr(input_text, search_string);    

if (searchPtr)  //if string to be searched is found

 {  printf("\nThe text line beginning with the first occurrence of %s: ", search_string);  

//prints the first occurrence of that search_string in input_text

 printf("%s\n", searchPtr);  

//search for the search_string in the rest of the input_text

 searchPtr = strstr(searchPtr + 1, search_string);        

 if (searchPtr)  // if search_string is found in input_text again  {

printf("\nThe text line beginning with the second occurrence of %s:\n", search_string);  

//display the second occurrence of the search_string in input_text

  printf("%s\n", searchPtr);   }

 else  //if search_string only appeared once in input_text

  printf("The string to be searched just appeared once.\n");  }

else  //if string to be searched is not found anywhere in input_text

 printf("\"%s\" cannot be found.\n", search_string);  }

Explanation:

The program first prompts the user to enter a line of text and a string to be searched in the line. When the user enters text and search string then search string is located in input text using strstr() function. If the first occurrence of search string is found then the remainder of the line of text beginning with the search string is displayed. Then strstr is used again to locate the next occurrence of the search string in the input_text.

The output of program is attached.

You might be interested in
SMART PEOPLE NEEDED
mario62 [17]
D doesn't make much sense, it's valid, but not what we're looking for. B also has a correlation with D, same reasoning applies. As for A, it seems pretty legit, but I don't believe that's what we're looking for.

Choice C is the most obvious one though. We're talking about a network and as may or may not know it's a wireless one in a manner of speaking. A <span>couple of computers in the network that have trouble maintaining a signal will indefinitely lead to failure of a network since both the links and nodes of certain computer systems are incapable of maintaining a signal. </span>
6 0
3 years ago
Determine the value of X if (211) base x = (152) base 8, how to do this?
Alex
 we translate the following statement given in terms of logarithms. 211 base x can be expressed into log 211 / log x while 152 base 8 can be expressed int o log 152 over log 8. In this case,
log 211 / log x = log 152 / log 8log x = 0.962x = 10^0.962 = 9.1632
7 0
3 years ago
In an all-integer linear program,
xenn [34]

Answer: E

All decision variables must be integer

Explanation:

The integer-linear program is a program in which the objective function and any constraints are all linear ie all of the variables are restricted to be integers.

A linear program is Np complete. Also every decision variable appear in any constraints must also appear in the objective function, possibly with zero coefficient if needed.

8 0
4 years ago
The distance between the center of the two circular bases should be 10 units to the right and 5 units up.
Vikentia [17]

Answer: 10,5,0

Explanation: i think its 10,5,0

srry if its wrong

3 0
2 years ago
Which program will have the output shown below?
MariettaO [177]

Answer:

for count in range(12,15)

Explanation:

This is a 'For' loop in python programming language and it take two or three arguments, the include: start, stop, step)

from the options given we only have two arguments (start, stop)

from my answer, the loop will begin from 12 and ends at (n-1) that's why it prints out 12, 13, and 14 only.

7 0
3 years ago
Other questions:
  • Elena is used to kissing her friends on both cheeks as a form of greeting in her native country. She notices that her new friend
    6·1 answer
  • Select the correct answer. Which character type is usually seen more often in games for young children than for the other age gr
    13·1 answer
  • In the software development life cycle, what is the role of participants in the planning phase? The participants’ role in the pl
    6·1 answer
  • The cost of large ground based telescopes has remained the same since the 1800's costing the equivalent of about a billion dolla
    9·1 answer
  • Why are high-quality transformers wound with large diameter wire?
    8·1 answer
  • apple and adobe are in disagreement about the use of __________ to create apps for the iphone and ipad?
    10·1 answer
  • An acronym is a word formed by taking the first letters of the words in a phrase and making a word from them. For example, AGH i
    10·1 answer
  • Plz tell me how to get my deleted account back you will be highly PRAISED!!!!!!!!!!
    14·2 answers
  • An open intersection is one that
    9·2 answers
  • Shane is working on a new project for the sales department. The company wants a way to allow the sales force to print orders at
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!