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
Writing in Java, write a program that prompts the user to input an integer and then outputs both the individual digits of the nu
larisa [96]

Answer:

//Here is code in java.

import java.util.*;

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

   try{

       int in;

     //scanner class object to read the input

    Scanner scr=new Scanner(System.in);

     // variable to keep running total

    int total=0;

    System.out.println("please enter an Integer:");

     // read the input first time

    in=scr.nextInt();

    System.out.print("individual digits of "+in+" is ");

    if(in<0)

    {

        in=-(in);

    }

   

 

     //call the function to print the digits of number

   print_dig(in);

   System.out.println();

    //calculate the sum of all digits

   do{

       int r=in%10;

       total=total+r;

       in=in/10;

   }while(in>0);

    //print the sum

   System.out.println("total of digits is: "+total);

     

   }catch(Exception ex){

       return;}

}

 //recursive function to print the digits of number

public static void print_dig(int num)

{  

    if(num==0)

    return;

    else

    {

    print_dig(num/10);

    System.out.print(num%10+" ");

    }

}

}

Explanation:

Read a number with the help of object of scanner class.if the input is negative

then make it positive number before calling the function print_dig().call

the recursive method print_dig() with parameter "num".It will extract the digits

of the number and print then in the order. Then in the main method, calculate

sum of all the digits of number.

Output:

please enter an Integer:                                                                                                  

3456                                                                                                                      

individual digits of 3456 is 3 4 5 6                                                                                      

total of digits is: 18

please enter an Integer:                                                                                                  

-2345                                                                                                                      

individual digits of -2345 is 2 3 4 5                                                                                      

total of digits is: 14

6 0
2 years ago
3. Personal Trainer is very concerned about the security and protection of the information they collect in the new information s
Sever21 [200]

Answer:

Check the explanation

Explanation:

in order to make sure that the built into the new systems, the below input and output levels of security control have to be considered for personal trainers staff.

There are:

   Network Security

   Application security

   Physical security

   User security

   File security

   Procedural security

These securities levels are consistent and advantage in building the decisions regarding system security.

There are the following policies applied to each control:

Network Security: Network interface and traffic controlling, encryption of data.

Application Security: Verification of data input/output and update of software proceedings.

Physical Security: Security to servers, computers and physical environment.

User Security: Protection passwords and identify management skills.

File Security: Access Permission allocated to users and editing authorizations given to users.

Procedural Security: Certify safety protection to perform decision-making activities and document shredders.

Finally, consider another main point is depends the new system performance are system response time, throughput, bandwidth time and turnaround time.

7 0
2 years ago
When you connect to an unsecured wireless network, what might dishonest or unscrupulous computer users try to do?
loris [4]

Answer:

Hackers can snoop on data sent over your network.

Hackers can use your network to access your computer's files and system information.

Explanation: Unsecured Wireless connections are wireless connections which are have no passwords they are open to the general public,such networks can be very risky to use as it gives easy access to dishonest persons who can manipulate that opportunity to SNOOP ON DATA SENT OVER YOUR NETWORKS. They can use this hacking to fraudulently steal from your bank account and obtain your private information.

8 0
2 years ago
Pls help!! which of the following is not a step required to view a web page?
Fofino [41]
The first one! It’s not required to view web pages
3 0
2 years ago
Create a list words = ['is', 'NLP', 'fun', '?']. Use a series of assignment statements (e.g. words[1] = words[2]) and a temporar
Svetlanka [38]

Answer:

words = ['is', 'NLP', 'fun', '?']

tmp = words[1]

words[1] = words[0]

words[0] = tmp

words[3] = '!'

print(words)

Explanation:

- Create the list

- Assign the new values using <em>tmp</em> variable

- Print the result

Since tuples in Python are unchangeable, you cannot transform the list using tuple assignment.

5 0
2 years ago
Other questions:
  • Using evidence to dispel myths or false beliefs is one way to move closer to evidence-based practice. Please select the best ans
    13·2 answers
  • Your computer has a quad-core processor that supports multithreading installed. given that the system is running windows, how ca
    6·1 answer
  • A ____ partition contains the data necessary to restore a hard drive back to its state at the time the computer was purchased an
    8·2 answers
  • Write a program in c or c++ to perform different arithmeticoperation using switch statement .the program will take two inputinte
    10·1 answer
  • The main problem with radio transmission is which of the following? Select one: a. Radio waves cannot travel through walls. b. W
    9·2 answers
  • Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value
    15·1 answer
  • The OSI security architecture provides a systematic framework for defining security attacks, mechanisms, and services. True or F
    12·1 answer
  • Your network administrator finds a virus has been successfully inserted into the network software. The virus itself is now consi
    10·2 answers
  • E-mail is an efficient means of disseminating information quickly and inexpensively. However, HIPAA regulations affect e-mail us
    13·1 answer
  • A retailer is able to track which products draw the most attention from its customers through the use of 5g-enabled motion senso
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!