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
The data in a data warehouse have which of the following characteristics?
Marina CMI [18]
What are the options it says which of the following characteristics.
4 0
3 years ago
User can use ______ commands to search for and correct words in a document
Maksim231197 [3]
Find and replace is the answer
5 0
3 years ago
Which logging category does not appear in event viewer by default?
Ulleksa [173]

I believe this should have some multiple choice options: Application, System, Volume, Security.


The correct answer is volume.

7 0
3 years ago
____ storage is not recommended for long-term archiving because the storage media can degrade over time
Lunna [17]

Hard Drive is not recommended for long-term archiving because the storage media can degrade over time,

<h3>What type of storage is recommended for long term data retention?</h3>

The long method used to long-term retention is the use of cloud. Cloud-based are known to be a form of cold storage that is made up of intelligent storage software.

Note that Hard Drive is not a long term kind of storage in the above context and as such, PE storage is not recommended for long-term archiving because the storage media can degrade over time,

Learn more about storage from

brainly.com/question/1317328

#SPJ1

5 0
2 years ago
A radio and communications security repairer is responsible for both radio and satellite communication systems.
natita [175]
I'm almost certain the answer is true
3 0
3 years ago
Read 2 more answers
Other questions:
  • _ includes websites that encourage interaction and connection among people, businesses, and organizations.
    5·1 answer
  • Which symbol is used to separate a worksheet name from a cell reference?
    10·1 answer
  • reate a class called Plane, to implement the functionality of the Airline Reservation System. Write an application that uses the
    5·1 answer
  • When you access the programs and documents on a computer by what way of icons is said to be employing
    6·1 answer
  • Tips for being confident and entertaining when presenting?
    6·1 answer
  • Pick the simplest line of code to test if the word "BASIC" is stored in the variable text1.
    12·1 answer
  • Translation of a file into a coded Format that occupies less space than the original file is called
    6·1 answer
  • 12. In cell A14, use the INDEX function and structured references to display the value in the first row and first column of the
    8·1 answer
  • Write a program that asks the user for the name of a file. The program should display the contents of the file with each line pr
    13·1 answer
  • The files in James's computer were found spreading within the device without any human action. As an engineer, you were requeste
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!