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]
2 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]2 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
Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a semicolon (no s
Pavlova-9 [17]

Answer:

Replace /* Your code goes here */  with

for(i =0; i<NUM_VALS; i++) {

    printf("%d", origList[i]*offsetAmount[i]);

printf(";");

}

Explanation:

The first line is an iteration statement iterates from 0 till the last element in origList and offsetAmount

for(i =0; i<NUM_VALS; i++) {

This line calculates and print the product of element in origList and its corresponding element in offsetAmount

    printf("%d", origList[i]*offsetAmount[i]);

This line prints a semicolon after the product has been calculated and printed

printf(";");

Iteration ends here

}

5 0
2 years ago
____ is a program placed on a computer without the user's knowledge that secretly collects information about the user
Scrat [10]
<span>Spyware is a program placed on a computer without the user's knowledge that secretly collects information about the user.
</span><span>The spyware gathers information and can send this information to another program or entity which can take control over the device or use personal information to harm the user. </span>
7 0
2 years ago
Which task can a company perform with intranets?
gregori [183]
I would probably say C, Though you might want a second, person to clarify. But My answer is C..
6 0
2 years ago
Read 2 more answers
The word “computer” has become associated with anything related to screens and keyboard. However, these are not the only parts t
Digiron [165]

Explanation: The CPU is the main control chip which calculates what has to be done in order for your computer to function.

(Very interesting question you had. Hope this answer helps)

4 0
2 years ago
Acceleration is the rate at which an object changes its velocity. It is typically represented by symbol a and measured in m/s2 (
Natalija [7]

Answer:

<u>Pseudocode:</u>

INPUT velocity

INPUT time

SET velocity = 0.44704 * velocity

SET acceleration = velocity / time

SET acceleration = round(acceleration, 1)

PRINT acceleration

<u>Code:</u>

velocity = float(input("Enter a velocity in miles per hour: "))

time = float(input("Enter a time in seconds: "))

velocity = 0.44704 * velocity

acceleration = velocity / time

acceleration = round(acceleration, 1)

print("The acceleration is {:.2f}".format(acceleration))

Explanation:

*The code is in Python.

Ask the user to enter the velocity and time

Convert the miles per hour to meters per second

Calculate the acceleration using the formula

Round the acceleration to one decimal using round() method

Print the acceleration with two decimal digits

7 0
2 years ago
Other questions:
  • One of the most toxic components of a computer is the
    11·1 answer
  • Is used to process certificates and private/public key information?
    12·1 answer
  • The ________ method is based on simple arithmetic. The process involves dividing the bits of a frame into equal segments, adding
    11·1 answer
  • Mathematical computations by a computer are faster than your quickest mathematical computations because the top speed of a neura
    13·1 answer
  • Write a method called printReverse that accepts a String as its parameter and prints the characters in opposite order. For examp
    9·1 answer
  • The Paste Options button labeled ____ is used if you want the pasted chart not to be linked to the source document but you want
    9·1 answer
  • FTP requires confirmation that a file was successfully transmitted to a client, but it has no built-in mechanism to track this i
    5·1 answer
  • Which would be the most efficient way to store files on your computer?
    13·2 answers
  • Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in t
    10·1 answer
  • What missing condition will give you the output shown?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!