1answer.
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
boyakko [2]
3 years ago
5

Write a C program (doublecopy) that allows a user to extract some part of an existing file (fileSource) and copy it twice to a n

ew file fileTarget. The user can specify (1) the number of bytes (num1) as an offset from the beginning of filesource, (2) how many bytes (num2) that will be extracted from it, and ,(3) the new fileTarget name. >doublecopy num1 num2 filesource fileTarget

Computers and Technology
1 answer:
Slav-nsk [51]3 years ago
3 0

Answer:

Check the explanation

Explanation:

#include <stdio.h>

#include <sys/stat.h>

#include <stdlib.h>

#include <fcntl.h>

#include <errno.h>

#include <unistd.h>

extern int errno;

struct stat st;

int main(int argc, char **argv){

  int num1 = atoi(argv[1]); // Getting num1 from user

  int num2 = atoi(argv[2]); // Getting num2 from user

  char *fileSource = argv[3];

  char *fileTarget = argv[4];

 

  int source_fd = open(fileSource, O_RDONLY); // opening the file in read only mode

  int target_fd = open(fileTarget, O_WRONLY | O_CREAT); // opening the target file in Writeonly mode if file is not found it will create

   

  char *ch = (char *) calloc(num2+num1, sizeof(char));

 

  stat(fileSource, &st);

  if(st.st_size < (num1 + num2)){

      printf("File Size is smaller than the specified bytes\n");

      read(source_fd, ch, st.st_size); // reading the file upto the end

      write(target_fd, ch, st.st_size); // write to the file

      write(target_fd, ch, st.st_size); // two times writing to the file

  }else{

      if(lseek(source_fd, (off_t)num1, SEEK_SET) < 0 ) // moving the cursor to after the specified bytes from the start

      {

          printf("Some Error occured while seeking the file");

          return -1;

      }

      read(source_fd, ch, num2); // reading num2 bytes from the source

      write(target_fd, ch, num2); // writing two times to the target

      write(target_fd, ch, num2);

     

  }

 

  return 0;

 

}

1 2 #include <stdio.h> #include <sys/stat.h> #include <stdlib.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> 4

The code screenshot and code output are attached below.

You might be interested in
What is the main purpose of the design of a water hose?
Liono4ka [1.6K]
The water hose is a flexible tube for conveying a liquid, as water. The main purpose of the design of a water hose is functionality.
The reason why the water hose is <span>designed is: to carry fluids from one location to another. the aesthetics is not so important, as the fact that the fluid will be carried without leakage.</span>


7 0
3 years ago
Read 2 more answers
Peripherals are part of the main computer.<br><br> True<br> False
LenKa [72]

Answer:

False

Explanation:

Peripherals are devices outside the main computer. They add to the functions of the main computer but the main computer can still power on without them. So this is how you can distinguish what is part of the main computer.

Peripherals can come as input or output devices. Input devices are devices like the keyboard, mouse, and the like. Output devices are things like scanners, printers, monitors, speakers and the like.

3 0
3 years ago
Read 2 more answers
A manager would like information on the knowledge base searches conducted by customers and call center agents. Which two metrics
RideAnS [48]

Answer:

Option A and Option D are the correct options.

Explanation:

While any information is provided by the manager to its customers which is based on the knowledge of the search conducted.

So, the following knowledge is about the article of the lowest rating and about the search query that has no output.

  • Option B is not correct for the following scenario because the manager is informing about the searches conducted by customers, not for the data category.
  • Option C is not correct for the following scenario because the articles are not created by them.
3 0
3 years ago
The ________ phase in a project involves documenting lessons learned from the project, so that the experience is useful to other
pentagon [3]

Answer:

C. Closing

Explanation:

Closing phase is the process of concluding all activities for a project, phase, or contract.  The key benefits of this are the project or phase information is archived, the planned work is completed, and organisational team resources are released to pursue new endeavours.  This process is performed once or at predefined points in the project.

The activities necessary for the administrative closure of the project or phase include:

Actions necessary to satisfy completion or exit criteria for the closing phase of a project are :

  • Ensuring that all documents are up-to-date and that all issues are resolved;
  • Confirming the delivery and formal acceptance of project by the client;
  • Ensuring that all costs are charged to the project;
  • Closing project accounts;
6 0
3 years ago
Here is the list of problems to choose from:
olya-2409 [2.1K]

Answer:

There's a parking lot that is 600m² big. The lot must be able to hold at least 3 buses and 10 cars.

Each car takes up 6m² and each bus takes up 30m².

However, there can only be 60 vehicles in the lot at any given time.

The cost to park in the lot is $2.50 per day for cars and $7.50 per day for buses. The lot must make at least $75 each day to break even.

What is a possible car to bus ratio that would allow the lot to make profit?

3 0
3 years ago
Other questions:
  • Why is it important to back up data on a computer before you burn-in test the cpu?
    9·1 answer
  • The central device on a network that provides a common connection point for nodes on that network is called the
    8·1 answer
  • Which of the following is a proper use of the application NetStumbler?Which of the following is a proper use of the application
    10·2 answers
  • Spelling and grammar checking options can be controlled at the word options dialog box. To display this dialog box, begin by cli
    15·1 answer
  • Create an application named TestClassifiedAd that instantiates and displays at least two ClassifiedAd objects. A ClassifiedAd ha
    8·1 answer
  • What is the first step you should take when you want to open a savings account make your initial deposit go to the bank and fill
    9·1 answer
  • What have very strong chemical bonds and cannot be reshaped when heated.​
    6·1 answer
  • Write a program that: Takes the list lotsOfNumbers and uses a loop to find the sum of all of the odd numbers in the list (hint:
    5·1 answer
  • Which file extension would be used to indicate a webpage document?.
    12·1 answer
  • Evaluation, formatting, expanding/decoding, distillation/reduction, and assessment are examples of ________ computing operations
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!