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
System software can be described as end-user software and is used to accomplish a variety of tasks.
irina [24]
Your answer is false :)

I hope this helps! :)
8 0
3 years ago
Is the computer a device that calculates and has the independence and initiative for the actions it performs?
inna [77]

Answer:

The answer is "True".

Explanation:

In this question, the given statement is true because the computer is a device that receives information as input, analyzes information utilizing a program that provides relevant information for the processed data, and in this, it performs numerous calculation and all the calculation will be store in its memory, which is used in the future for collect data on hard drives.

8 0
3 years ago
Instant messaging is synchronous
ASHA 777 [7]
True; synchronous means existing or occurring at the same time (I really don't know if that's a question but oh well) 
7 0
3 years ago
What is the difference between computer architecture and computer organization?
alukav5142 [94]
The distinction between "computer architecture" and "computer organization" has become very fuzzy, if no completely confused or unusable. Computer architecture was essentially a contract with software stating unambiguously what the hardware does. The architecture was essentially a set of statements of the form "If you execute this instruction (or get an interrupt, etc.), then that is what happens. Computer organization, then, was a usually high-level description of the logic, memory, etc, used to implement that contract: These registers, those data paths, this connection to memory, etc. Programs written to run on a particular computer architecture should always run correctly on that architecture no matter what computer organization (implementation) is used. For example, both Intel and AMD processors have the same X86 architecture, but how the two companies implement that architecture (their computer organizations) is usually very different. The same programs run correctly on both, because the architecture is the same, but they may run at different speeds, because the organizations are different. Likewise, the many companies implementing MIPS, or ARM, or other processors are providing the same architecture - the same programs run correctly on all of them - but have very different high - level organizations inside them.
8 0
3 years ago
Read 2 more answers
Which function of a web page relies on responsive web design
navik [9.2K]

Answer:

Adding extra horizontal scroll, Blocking mobile devices from viewing, Eliminating extra links, Resizing content to fit a screen.

Explanation:

3 0
3 years ago
Other questions:
  • In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the mont
    14·1 answer
  • Have you ever used a device that relies solely on the cloud?
    10·1 answer
  • Businesses use a fax cover sheet is to _____. provide detailed service and product information make sure message reaches the rig
    14·2 answers
  • You are unpacking and setting up workstations
    13·1 answer
  • Consider the following code segment. for (int a = 0; a &lt; 10; a++) { for (int b = 10; b &gt; a; b--) { System.out.print("#");
    6·1 answer
  • Which of the following statements about electronic cover letters is true?
    14·2 answers
  • Identify a stressor in your life. Conduct an internet search to locate at least two reliable sources of information on effective
    6·1 answer
  • What is the data and information with example? ​
    9·1 answer
  • How to do GCD on small basic?​
    7·1 answer
  • Write any two rules for writing algorithm​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!