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
RideAnS
7 days 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:
amid [800]7 days ago
7 0

Answer:

Refer to the explanation

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
You want to register the domain name ABCcompany.org, but the registration service is not allowing you to do that. What's the mos
amid [800]

Options :

The domain name is already taken.

Domain names are required to end with ".com".

You do not hold legal ownership of ABC Company.

Domain names must exclusively use lowercase letters.

Answer:

The domain name is already taken.

Explanation: In the above scenario, ABCcompany.org signifies the domain associated with a specific individual or organization that leads to the owner's website. Each domain name must be unique; therefore, no two different entities or individuals can have identical domain names. Domains can have endings like .com, .org, .ng, and more, and they are not case-sensitive. Thus, the inability to register the mentioned domain is probably because it has already been claimed by someone else.

6 0
1 month ago
Use the following data definitions data myBytes BYTE 10h,20h,30h,40h myWords WORD 3 DUP(?),2000h myString BYTE "ABCDE" What will
Natasha_Volkova [897]

Answer:

Given Data:

myBytes BYTE 10h, 20h, 30h, 40h

myWords WORD 3 DUP(?), 2000h

myString BYTE "ABCDE"

From the supplied information, we can derive that:

(a).     a. EAX = 1

         b. EAX = 4

         c. EAX = 4

         d. EAX = 2

         e. EAX = 4

         f. EAX = 8

         g. EAX = 5

8 0
18 days ago
A user calls the help desk and reports that the workstation, when powering up, displays error messages about an invalid system d
ivann1987 [930]

Answer:

Option (A) is the correct choice.

Explanation:

The situation describes an invalid boot disk error occurring during startup, indicating that the system fails to recognize the hard disk necessary for booting.

MBR / GPT is the partition layout that holds the essential code for system startup. Occasionally, the partition files that contain this code may become corrupt, causing an invalid boot disk error during the boot process.

Therefore, the most fitting answer is option (A).

The remaining choices are incorrect for these reasons:

  • If the boot system malfunctions, it cannot produce an invalid boot disk error.
  • If the files of the operating system are corrupted, the error will pertain to missing files.
  • A device driver cannot influence the system's booting process.
5 0
1 month ago
Assume a machine during its initial testing phase produces 10 widgets a day. After 10 days of testing (starting on day 11), it b
Harlamova29_29 [932]

Response:

Python Code:

n = int(input("Days: "))

total = 0

for i in range(1,n+1):

     if i <= 10:

           total += 10

     elif i <= 60:

           total += 40

     elif i <= 99:

           total += 100 - i

print(str(total)+ " widgets")

Clarification:

This line requests user input for the number of days.

n = int(input("Days: "))

This line sets the initial total number of widgets to zero.

total = 0

The subsequent loop calculates total widgets based on the established rules.

for i in range(1,n+1):

     if i <= 10: -> Applies when days are 10 or fewer

           total += 10

     elif i <= 60: -> Applies when days are between 11 and 60

           total += 40

     elif i <= 99: -> Applies when days are under 100

           total += 100 - i

This line outputs the total count.

print(str(total)+ " widgets")

4 0
28 days ago
1.the following code example would print the data type of x, what data type would that be?
Natasha_Volkova [897]

Answer:

x = 5, so the data type is integer (used for whole numbers)

2. The data type in question is string

3. The data type is float (used for decimal numbers)

Explanation:

6 0
1 month ago
Other questions:
  • Which of these is an example of the integrity principle that can ensure your data is accurate and untampered with?
    10·2 answers
  • Allan needs to ensure that an object is in a very precise location on a slide. He decides to use the Ruler option to achieve thi
    5·2 answers
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • 5.15 LAB: Output values below an amount Write a program that first gets a list of integers from input. The input begins with an
    9·2 answers
  • Sophie often makes grammatical errors in her document. Which feature of the Spelling and Grammar tool can she use to understand
    15·2 answers
  • Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to
    7·1 answer
  • Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only
    9·2 answers
  • Write a program in pascal to find the area of a circle
    14·1 answer
  • A wireless network was recently installed in a coffee shop and customer mobile devices are not receiving network configuration i
    12·1 answer
  • James is an intern in a film production company. On his first day, James’ boss, Monica, tells him, “Before anything else, let me
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!