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
Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of in
MAXImum [283]

Answer:

B. {1, 2, 2, 3, 3, 4, 5}

Explanation:

Given

The above code segment

Required

Determine which list does not work

The list that didn't work is B.\ \{1, 2, 2, 3, 3, 4, 5\}

Considering options (A) to (E), we notice that only list B has consecutive duplicate numbers i.e. 2,2 and 3,3

All other list do not have consecutive duplicate numbers

Option B can be represented as:

nums[0] = 1

nums[1] = 2

nums[2] = 2

nums[3] = 3

nums[4] = 3

nums[5] = 4

nums[6] = 5

if (nums.get(j).equals(nums.get(j + 1)))

The above if condition checks for duplicate numbers.

In (B), when the elements at index 1 and 2 (i.e. 2 and 2) are compared, one of the 2's is removed and the Arraylist becomes:

nums[0] = 1

nums[1] = 2

nums[2] = 3

nums[3] = 3

nums[4] = 4

nums[5] = 5

The next comparison is: index 3 and 4. Meaning that comparison of index 2 and 3 has been skipped.

<em>This is so because of the way the if statement is constructed.</em>

3 0
3 years ago
What is Microsoft word<br>​
Snowcat [4.5K]

Answer:

A software where you can document letters, essays or anything really.

Explanation:

5 0
3 years ago
Read 2 more answers
Two ways of selecting text with mouse​
AVprozaik [17]

Answer:

hold down left click and drag or double/triple click the text

Explanation:

4 0
2 years ago
Even with a good protocol, what are some privacy and security challenges while playing battleship on the internet simulator?
sweet [91]
<span>The Internet Simulator “broadcast” every message to every person in the group. Even with a good protocol, there are some privacy and security challenges while playing battleship on the internet simulator. Some of them are:</span><span>
- Broadcast mode allows all users to see all of the moves in plain text
- You do not know exactly who the message came from</span>

3 0
3 years ago
Read 2 more answers
To adapt to dimmer light with a film camera would be more complicated than with a digital
Zinaida [17]

Answer:

Changing the _exposure_ to adapt to dimmer light with a film camera would be more complicated than with a digital camera.

Explanation:

Film Camera is heavier, and it can cost a lot if we want to adapt to dimmer light and shoot in that dimmer light. Digital cameras are cheaper. In the case of a Film Camera, you need to lower down the shutter speed, make adjustments related to the aperture, ensure that the camera does not shake a lot, make use of the faster lens, as well as adjust the while balances, and use certain different light source. And all this confirms that it is not that easy to do this with Film cameras, and they can cost a lot as well. Digital Cameras are cheaper, and a better option for you. And you need to change the exposure to adapt to less light with the film Camera, but this is much easier with the digital camera. You will soon find out if you use them.

5 0
3 years ago
Other questions:
  • Why was Windows 1.0 considered an operating environment rather than an operating system?
    10·2 answers
  • Why are there so many unit testing tools? Are they efficient? Why or why not?
    13·1 answer
  • Explain in detail what it means to synchronize computers and mobile devices. include at least two strategies for keeping your fi
    7·1 answer
  • Allie needs to add a long row of numbers. She should enter a
    13·2 answers
  • Kaitlin likes a particular design theme, but she is not sure about every single color for bullets, backgrounds, etc found in the
    5·2 answers
  • Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt t
    13·1 answer
  • The ____ option must be used when running a program in order to see the results of assert statements.
    7·1 answer
  • A disciplined, creative, and effective approach to problem solving is needed for project success. The nine-step approach to prob
    13·1 answer
  • Only one person can receive the same email at the same time true or false
    10·1 answer
  • What describes Accenture's approach to automation?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!