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
Fantom [35]
2 years ago
11

Write a program using the standard library I/O functions (fopen, fread, fwrite, fclose, ferror, feof, and fflush) to read a text

file and search it for a string (specified on the command line) in each line of an input file (whose name is also specified on the command line); if the string is found substitute another string (also specified on the command line) ONLY ONCE on the line.Write the output with the substitutions to the stdout, and write any errors to the stderr.
Computers and Technology
1 answer:
Serggg [28]2 years ago
7 0

Answer:

See explaination

Explanation:

#include <stdio.h>

#include <stdlib.h>

#include<string.h>

int main(int argc, char *argv[])

{

FILE *fr,*fr1,*fr3; /* declare the file pointer */

char filename[256];

char search[256];

char line[256];

int count=0;

char replace[256];

printf("Enter FileName: "); // ask for filename

scanf("%s",filename);

fr3 = fopen (filename, "r");

if(ferror(fr3)) //check for any error assosicated to file

{

fprintf(stderr, "Error in file"); // print error in stderr

printf("Error");

}

printf("Input file data is");

while(!feof(fr3)) // checking end of file condition

{ //printf("inside");

fgets(line,256,fr3) ;

printf("%s",line);

}

printf("\nEnter String to search: "); //ask for string to search

scanf("%s",search);

printf("Enter string with whom you want to replace: "); //ask for string with whom you want to replace one time

scanf("%s",replace);

fr = fopen (filename, "r"); // open first file in read mode

fr1 = fopen ("output.txt", "w"); //open second file in write mode

if(ferror(fr)) //check for any error assosicated to file

{

fprintf(stderr, "Error in file"); // print error in stderr

printf("Error");

}

while(!feof(fr)) // checking end of file condition

{ //printf("inside");

fgets(line,256,fr) ;

int r=stringCompare(line,search); // comparing every string and search string

// printf("%d",r);

if(r==1 && count==0)

{

fwrite(replace , 1 , sizeof(replace) , fr1 ); // writing string to file.

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

count++;

}

else{

printf("%s",line);

fwrite(line , 1 , sizeof(line) , fr1 );

}}

printf("\n");

fflush(fr1); // it will flush any unwanted string in stream buffer

fflush(fr);

fflush(fr3);

fclose(fr); //closing file after processing. It is important step

fclose(fr1);

fclose(fr3);

system("PAUSE");

return 0;

}

// Compare method which is comparing charaacter by character

int stringCompare(char str1[],char str2[]){

int i=0,flag=0;

while(str1[i]!='\0' && str2[i]!='\0'){

if(str1[i]!=str2[i]){

flag=1;

break;

}

i++;

}

if (flag==0 && (str1[i]=='\0' || str2[i]=='\0'))

return 1;

else

return 0;

}

You might be interested in
Write a destructor for the CarCounter class that outputs the following. End with newline.
ycow [4]

Answer:

Following are the code to this question:

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

Explanation:

Following are the full program to this question:

#include <iostream>//Defining header file

using namespace std;

class CarCounter //Defining class CarCounter

{

public:

CarCounter();//Defining constructor CarCounter

~CarCounter();//Defining destructor CarCounter

private:

int carCount;//Defining integer variable carCount

};

CarCounter::CarCounter()//declaring constructor  

{

carCount = 0;//assign value in carCount variable

return;//using return keyword

}

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

int main() //Defining main method

{

CarCounter* parkingLot = new CarCounter();//Defining class object parkingLot

delete parkingLot;//

return 0;

}

  • In the given C++ language code, a class "CarCounter" is defined, and inside the class, a "constructor, Destructors, and an integer variable" is defined.  
  • Outside the class, the scope resolution operator is used to define the constructor and assign value "0" in the integer variable.  
  • In the above-given code, the scope resolution operator, to define destructor and inside this cout function is used, which prints a message.  
  • In the main method, the class object is created, which automatically calls its class constructor and destructors.  
7 0
2 years ago
In a ____________________ attack, the attacker sends a large number of connection or information requests to disrupt a target fr
Blababa [14]

DDoS - Distributed Denial of Service

<u>Explanation:</u>

  • In DDoS attack, the attack comes from various system to a particular one by making some internet traffic.
  • This attack is initiated from various compromised devices, sometimes distributed globally through a botnet. It is different from other attacks  such as (DoS) Denial of Service attacks, in which it utilizes an unique Internet-connected device ( single network connection) to stream a target with the malicious traffic.
  • So in DDoS, multiple systems are involved in the attack and hence we can conclude that as the answer.
8 0
2 years ago
Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The fi
Snezhnost [94]

Answer:

Go to explaination for the program code.

Explanation:

Before running the program you need to have these files created like below in your unix box.

Unix Terminal> cat nouns.txt

BOY

GIRL

BAT

BALL

Unix Terminal> cat articles.txt

A

THE

Unix Terminal> cat verbs.txt

HIT

SAW

LIKED

Unix Terminal> cat prepositions.txt

WITH

BY

Unix Terminal>

Code:

#!/usr/local/bin/python3

import random

def getWords(filename):

fp = open(filename)

temp_list = list()

for each_line in fp:

each_line = each_line.strip()

temp_list.append(each_line)

words = tuple(temp_list)

fp.close()

return words

articles = getWords('articles.txt')

nouns = getWords('nouns.txt')

verbs = getWords('verbs.txt')

prepositions = getWords('prepositions.txt')

def sentence():

return nounPhrase() + " " + verbPhrase()

def nounPhrase():

return random.choice(articles) + " " + random.choice(nouns)

def verbPhrase():

return random.choice(verbs) + " " + nounPhrase() + " " + prepositionalPhrase()

def prepositionalPhrase():

return random.choice(prepositions) + " " + nounPhrase()

def main():

number = int(input('Enter number of sentences: '))

for count in range(number):

print(sentence())

if __name__=='__main__':

main()

kindly check attachment for code output and onscreen code.

6 0
2 years ago
Choose the correct sequence for classifier building from the following.
Alekssandra [29.7K]

Answer:

b

Explanation:

First, we need to initialize the classifier.

Then, we are required to train the classifier.

The next step is to predict the target.

And finally, we need to evaluate the classifier model.

You will find different algorithms for solving the classification problem. Some of them are like  decision tree classification  etc.

However, you need to know how these classifier works.  And its explained before:

You need  to initialize the classifier at first.

All kinds of classifiers in the scikit-learn make use of the method fit(x,y) for fitting the model or the training for the given training set in level y.

The predict(x) returns the y which is the predicted label.And this is prediction.

For evaluating the classifier model- the score(x,y) gives back the certain score for a mentioned test data x as well as the test label y.

8 0
2 years ago
Which are factors that go into a project plan? Choose four answers.
USPshnik [31]

Factors that go into a project plan

  • Estimate the scope of work, based on similar projects.
  • Make sure everyone takes responsibility.
  • Creating and defining team goal
  • Working to a budget

Explanation:

Project Estimating  : Every project is different, but that doesn’t mean you have to start from zero each time. The best way to make sure you’re on the right track is to approach it from every angle. Consider similar projects, talk to your team, and understand what the client is expecting and how they’d like things to go.

Managing your team size  : A smaller team is usually preferable as it puts your project in the most ideal position to be completed on time and at the quality you expect, without burning out your team members. A smaller team also reduces the number of communication channels, which means there’s less opportunity for misinterpretation or people simply missing something.  

Planning and managing your team resources  : That said, there may be a time when you don’t have the right resources in-house to do the job. Either they are fully allocated to another project or no one has the right skill set. In this situation you have two options, either bring in freelance contractors or hire a new employee to fill the role.  

Creating and defining team goals  : The planning phase is when you’ll want to work with the team to understand what their individual goals are for the project. Is there something different they’d like to try? A test or new idea they’d like the chance to prove? Or perhaps a roadblock they want to avoid?

Scheduling Tasks to a Project Timeline  : The timeline of the project will largely be determined by the client, as they often have deadlines they need to hit to meet certain business goals that are simply out of your control. However, setting clear expectations and agreeing on the timing of key deliverables is crucial.

7 0
2 years ago
Other questions:
  • Which statement best describes how the rapid prototyping model works?a) Developers create prototypes to show stakeholders how va
    11·2 answers
  • Which are examples of intrapersonal goals? Check all that apply. Lea plans to finish her next project before the due date. Erick
    12·2 answers
  • An administrator has initiated the process of deploying changes from a sandbox to the production environment using the Force IDE
    5·1 answer
  • The bit width of the LRU counter for a 32 KB 16-way set associative cache with 32 Byte line size is
    13·1 answer
  • A firm that wanted to enable its employees to use and share data without allowing outsiders to gain access could do so by establ
    14·1 answer
  • Which of the following facts determines how often a nonroot bridge or switch sends an 802.1D STP Hello BPDU message?
    14·1 answer
  • "online privacy alliance (opa) is an organization of companies dedicated to protecting online privacy. members of opa agree to c
    15·1 answer
  • A ______________ deals with the potential for weaknesses within the existing infrastructure to be exploited.
    10·2 answers
  • Accenture has partnered with a global construction company that specializes in building skyscrapers. The company wants better ma
    12·1 answer
  • Which are technical and visual demands that need to be considered when planning a project? Choose three answers
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!