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 Internet Engineering Task Force (IETF) defines the protocols and standards for how the Internet works. The members of the IE
belka [17]

<em>Answer:</em>

<em>A loosely organized collection of citizens and engineers who communicate mostly by email. </em>

Explanation:

6 0
3 years ago
Select the statement that best describes the function of the cell wall. O it gives shape to plants cells. O it produces food fro
Maslowich
It’s jelly like fluid surrounds the nucleus
8 0
3 years ago
1. Explain the difference between a web browser and a search engine. (2 points)
Elan Coil [88]

Answer:

1. A browser is used to access websites and web pages whereas a search engine is used to search for particular information.

2. Indexing is the process by which search engines organise information before a search to enable super-fast responses to queries.

3.Search engines are used to find specialized data rapidly whereas web directory is used to find a list of different sites.

4. The working behind the PageRank algorithm is that a page with a large number of in- links(a link from an important page) to it, then its outgoing links to other pages also become important. It gives more importance to back links of a web page and propagates the ranking through links.

5. Look for Sites from Established Institutions 2. Look for Sites with Expertise 3. Steer Clear of Commercial Sites 4. Beware of Bias 5. Check the Date 6. Consider the Site's Look 7. Avoid Anonymous Authors 8. Check the Links

Explanation:

5 0
3 years ago
An incurred cost that cannot be recovered, which is irrelevant for all decisions about the future, is included in the projected
iragen [17]

Answer:

An incurred cost that cannot be recovered, which is irrelevant for all decisions about the future, is included in the projected cost of a project. According to "Thinking Like an Economist," this an example of:<u> Failing to ignore sunk costs</u>

Explanation:

A sunk cost is a cost that cannot be recovered or changed and is independent of any future costs a business may incur. Since decision-making only affects the future course of business, sunk costs should be irrelevant in the decision-making process

3 0
3 years ago
To add a slide using the default layout, what should you do before clicking the New Slide button?
SIZIF [17.4K]

You have to add it and then there should be a layout button and you have to press that button

4 0
3 years ago
Other questions:
  • Jackie is planning a birthday party for her little brother and is researching different trampoline parks. She receives a pop-up
    12·2 answers
  • Why isn't my rank move from ambitious to virsto i met all the requirements
    8·2 answers
  • Corey is an architect. What software does he most likely use to design houses? graphic software scheduling software CAD software
    10·2 answers
  • You order a new personal computer. A representative from the store calls to ask if you need CD-copying software in your personal
    12·1 answer
  • Date criteria are automatically enclosed in ____ when entered in a query design.
    11·1 answer
  • A device receives a Transmission Control Protocol (TCP) packet. The device understands where the actual data payload begins. Whi
    15·1 answer
  • Which increases the rate of soil formation?
    10·1 answer
  • Write a function named reverse_list that takes as a parameter a list and and reverses the order of the elements in that list. It
    12·1 answer
  • How to identify mistakes in a html code??​
    14·1 answer
  • Va rog urgent
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!