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 output if the user types in 8
Lady_Fox [76]

Answer: 8

And if you hold shift while typing it, it gives *

7 0
3 years ago
Which of the following is NOT an advantage of central management of information systems in the University System of Georgia? (A)
zzz [600]

Answer:

Independence

Explanation:

Management information system (MIS) is the system that acts as the backbone of an organization's activities, holding everything together. According to my research on MIS, I can say that based on the information provided within the question the one term that is not considered an advantage would be Independence. Since MIS doesn't really provide independence since the organization depends on the system.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

6 0
3 years ago
What are the paragraph different formatting paragraph tools?draw its icon and state its function.
aliya0001 [1]

Theres Tab, And File


:)

7 0
3 years ago
Which of the following answers refers to a system containing mappings of domain names to various types of data, such as for exam
Dvinal [7]

Answer:

Option B: DNS

Explanation:

Domain Name Server (DNS) is analogous to a phone book where people can look up a person name through numerical phone number. A DNS server is a database that host a database of public IP addresses (e.g. 64.233.160.0) and their associated hostname (e.g. google.com).

Whenever we type domain name in the address bar of our browser (e.g. google.com), that domain will be delivered to DNS server. Inside DNS server the URL will be mapped with its corresponding IP address making it possible for the web request to reach the the target server.

6 0
3 years ago
How has the manufacturing process of cell phones evolved over time? What factors have influenced these changes? *
kicyunya [14]

Answer:

Cellphones have evolved rapidly since handheld mobile phones first appeared in the 1970s. ... Generally, phones have evolved to be more compact, to have longer battery life and to allow addition of features beyond making calls, like running apps and sending text messages.

Explanation:

7 0
3 years ago
Other questions:
  • Use your own words to describe how IT/IS can support major functional areas in the business. Discuss at least two of these areas
    14·1 answer
  • Need help with this file and due today!!
    6·1 answer
  • Janelle is shopping for jeans from Express. She clicks on a style she likes. The site quickly presents her with a close-up view
    5·1 answer
  • What port number is the web server listening on for the web request?
    9·1 answer
  • GenXTech is a growing company that develops gaming applications for military simulations and commercial clients. As part of its
    8·1 answer
  • A group of developers for a startup company store their source code and binary files on a shared open-source repository platform
    14·1 answer
  • What does running the “sudo” command do?
    6·1 answer
  • How was the Big Ben project similar to the investigation you conducted in class to determine if the table was vibrating? How is
    7·1 answer
  • What is the best description of a programming language?
    15·1 answer
  • which classification of money describes money that can be accessed quickly and easily, and includes coins and paper money as wel
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!