answer.
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]
1 year 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]1 year 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
You have been employed as a technical consultant to a computer shop chain. You are given the task of creating a short consumer b
brilliants [131]

Answer:

The five factors to consider when trying to choose between a Solid State Drive, a Hard Disk Drive and, an External Hard Disk Drive are:

  1. Read/Write Speed
  2. Weight
  3. Power Consumption
  4. Cost
  5. Storage Capacity

  • Solid State Drives (SSDs) are typically lighter in weight, faster and do not consume much power.
  • Hard Disk Drives are relatively cheaper than SSDs. They also come with higher storage capacities but are more power-hungry and slower because they rely on mechanical/moving parts to read and write data.
  • External HDDs are the cheapest of the three. They are not internal which is a major drawback given the additional weight. However, they come with gargantuan storage capacities that make you want to rethink having one. Besides, unlike SSDs, you can easily get them in computer accessories shops offline or online.

Cheers!

3 0
2 years ago
Your computer has gradually slowed down. What's the most likely reason?
sweet-ann [11.9K]
It could be old ... could be your connection to the internet... could be a virus. You can go to walmart or your super store and buy a usb for your computer. There are ones that can speed up your computer. I had to buy it for mine and it worked. It might be over 20 dollars depends on where you go.
8 0
2 years ago
You can apply several different worksheet themes from which tab?
Lemur [1.5K]
<span>D. Page Layout  i hope this helps </span>
8 0
2 years ago
Read 2 more answers
Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, prin
iogann1982 [59]

Answer:

import java.util.Scanner;

public class nu3 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter number of cycles");

       int numCycles = in.nextInt();

       //Call the method

       printShampooInstructions(numCycles);

   }

   public static void printShampooInstructions(int numCycles){

                if (numCycles<1){

              System.out.println("Too few");

          }

          if (numCycles>4){

              System.out.println("Too Many");

          }

          else {

              for (int i = 1;i <= numCycles; i++) {

                  System.out.println( numCycles+ ": Lather and rinse");

                  numCycles--;

              }

              System.out.println("     Done");

          }

   }

}

Explanation:

This is solved using Java programming language

The method printShampooInstructions() is in bold in the answer section

I have also provided a complete program that request user to enter value for number of cycles, calls the method and passes that value to it

The logic here is using if .... else statements to handle the different possible values of Number of cycles.

In the Else Section a loop is used to decrementally print the number of cycles

4 0
2 years ago
Axel is finally documenting his work. What could he be writing?
allochka39001 [22]

Answer: maybe his wrtting ezam

Explanation:

7 0
2 years ago
Other questions:
  • Of the following tasks, which one CANNOT be easily accomplished with a Wiki? Collaborating Social networking Editing Reading
    13·1 answer
  • In the game Beehive, you play the role of a worker bee who must watch over her hive. Your duties include (among others) directin
    12·2 answers
  • A computer is a multipurpose device that accepts input, processes data, stores data, and produces output, all according to a ser
    9·1 answer
  • There are many different types of hardware devices, different manufacturers, and countless configuration possibilities. Explain
    14·1 answer
  • The Web can play a significant role in making large amounts of information available to decision makers. Decision makers must be
    10·1 answer
  • You realize your computer has been infected with malware. It seems as if someone is controlling your computer from a remote loca
    5·1 answer
  • Consider the relation Courses(C, T, H, R, S, G), whose attributes can be thought of informally as course (C), teacher (T), hour
    10·1 answer
  • Lyrics = ["I wanna be your endgame", "I wanna be your first string",
    5·1 answer
  • Use the single-server drive-up bank teller operation referred to in Problems 1 and 2 to determine the following operating charac
    10·1 answer
  • A company decides to relocate its operations to another state in order to take advantage of some new business investment credits
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!