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
An expression which combines variables numbers and at least one operation
hichkok12 [17]

Answer:

An "Algebraic expression" is the correct answer for the above question.

Explanation:

  • The algebraic expression is an expression that is written in the form of alphabets and numbers. For example x+2x.
  • And it is also calculated with the consideration of alphabets like X+2X will be 3X.
  • The above question asked about the expression which is used with the combination of alphabets or variables and the numbers. That expression is known as "Algebraic expression"
4 0
3 years ago
Molly, a technician, has been tasked with researching an emulator for the software developers to test cross-platform application
Tresset [83]

Answer:

Option (C) and (D) are the correct answers.

Explanation:

Because Hypervisor is an application or software that provides you a platform by which you can operate another application or software which is not supported to the current operating system just like, you can operate the mobile applications on your system with the help of Hypervisor software. In other words, it is an emulator that provides you the platform to operate different applications on your system.

8 0
3 years ago
In which view are fields set up in MS Access?
Phantasy [73]

Answer:On the Home tab, in the Views group, click View, and then click Design View. In the table design grid, select the field or fields that you want to use as the primary key. To select one field, click the row selector for the field that you want.

Explanation:

7 0
3 years ago
Read 2 more answers
The browser feature which enables tabs to work independently from one another so if one crashes, the others may continue to work
Mars2501 [29]

Answer:

Tab isolation

Explanation:

Tab isolation is a feature of the browser that works to protect your data from malware. its uses to enhance the reliability of the browser by considering the impact of the crash.

A browser without the tab isolation can be crash fully due to the crashing of one tab. this feature helps to recover the previous opening tab after crashing while on the previous version of the browser if one tab crashes then it automatically crashes all other tabs.

8 0
3 years ago
Some email programs let you use a ____ to move incoming mail to a specific folder or to delete it automatically based on the con
KatRina [158]

Answer:

filter

Explanation:

Some email programs let you use a filter to move incoming mail to a specific folder or to delete it automatically based on the content of the message.​

The filter performs this role by either automatically deleting or moving to another location.

Most messages that are moved or deleted are unsolicited emails or spam messages.

Filtering of your mails helps so you ou can manage your incoming mail using filters to send email to a label, or archive, delete, star, or automatically forward your mail.

This is a way of organising your correspondence.

6 0
3 years ago
Other questions:
  • Walking paths across the part is represented by the equation why equals -4x - 6​
    9·1 answer
  • Eniac was the first desktop computer. t/f
    5·1 answer
  • Which of the following TCP/IP settings should be configured to specify DNS suffixes to use other than resolving names through a
    9·1 answer
  • Jayden wants to take a current theme but just change a little bit of it. Complete the steps to help Jayden.
    10·1 answer
  • Given the following sets, for each set operation provide the elements of the resulting set in set notation or using a well-known
    5·1 answer
  • The instructions for a computer program are sometimes referred to as . computer programmers focus on computer programs, but they
    5·2 answers
  • Video-sharing sites such as youtube and vimeo provide a place to post short videos called clips, true or false?
    10·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • Write a program, TwoDimentionalGrid. Ask the user to enter the size of the 2 dimensional array. Here we are not doing any input
    13·1 answer
  • PLEASE HELP. Nobody has been helping me, i need to resolve this code issue for game design
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!