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
3.24 LAB: Seasons
AveGali [126]

Answer:

Seasons Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid Invalid The dates for each season are: Spring: March 20 - June 20 Summer: June 21 - September 21 Autumn: September 22 - December 20 Winter: December 21 - March 19 LAB ACTIVITY 3.24.1: LAB: Seasons 0/10 main.cpp Load default template... 1 #include eam> 2 #include <string> 3 using namespace std; 4 5 int main() 6 string inputMonth; 7 int inputDay; 8 9 cin >> inputMonth; 10 cin >> inputDay; 11 12 /* Type your code here. */ 13 14 return; 15 }

3 0
2 years ago
Which part of project management considers if employees will work at home or in the office?
gregori [183]

Answer: i think its resources

Explanation:

5 0
2 years ago
Read 2 more answers
In this activity, you will submit the work you completed for the "Explore: Products" assignment. Type your response directly int
BabaBlast [244]

It should be noted that mate is the national beverage of countries such as Uruguay, Paraguay, and Argentina.

<h2>What is mate?</h2>

Mate tea is simply a beverage that is high in antioxidants and also contains caffeine.

It should be noted that mate is important as it raises morale, helps in sustaining the muscular system, and also allows an individual endure privations.

In conclusion, the drink is also usually taken by sportsmen.

Learn more about beverages on:

brainly.com/question/25884013

6 0
2 years ago
Can someone please help with one? I will mark brainlest!!!
Snowcat [4.5K]

I want to say that it is data authenticity?

4 0
3 years ago
Read 2 more answers
In the tcp/ip protocol that allows communication across the internet, what does tcp do?
DedPeter [7]

TCP tells or state how applications can make channels of communication across a network.

<h3>What is the role of TCP?</h3>

TCP is known to often help in the management of how a message is put together into smaller packets before they are sent or transmitted over the internet and then put together again in the right way at the arriving or destination address.

Therefore, TCP tells or state how applications can make channels of communication across a network.

Learn more about TCP from

brainly.com/question/17387945

#SPJ11

7 0
2 years ago
Other questions:
  • Do most facebook and twitter users access the platform from their personal computers?
    6·2 answers
  • Need help writing a program that reads a string if the option "E" (enter a string) is chosen, and checks if parentheses (), brac
    14·1 answer
  • Give an example of an input device, an output device, a storage device, and a networking device.
    10·1 answer
  • Assume that LO and HI have already been assigned as constants with LO &lt; HI, and x has been declared as DWORD in the data segm
    7·1 answer
  • 5. Pins on Pinterest can be linked to
    8·1 answer
  • The goal expressed in this definition states that data visualization is about ________________ .
    11·2 answers
  • Question # 7
    11·1 answer
  • Specifications that establish the compatibility of products and the ability to communicate in a network are called:
    10·1 answer
  • Write a class Bug that models a bug moving along a horizontal line. The bug moves either to the right or left. Initially, the bu
    13·1 answer
  • When passing a list of parameters to a stored procedure by name, you can omit optional parameters by:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!