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]
2 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]2 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
How do I find unwanted programs on my computer?
Nataliya [291]

To find unwanted programs on my computer, you can find them from either the start menu, setting, or control panel.

Regardless of how old or new your computer is, it will undoubtedly contain at least one program that you don't require. You might try a different site if you can't locate the method you're looking for because there are various ways to remove apps and programs. Be aware that some applications and programs are part of Windows and cannot be removed.

If a program is just not functioning as it should, you can try to repair it first.

  • From the Start menu, remove

Search for the app in the displayed list by selecting Start > All apps.

Select Uninstall by pressing and holding (or right-clicking) the application.

  • Remove in Settings

Start > Settings > Apps > Apps & features should be selected.

Locate the app you wish to uninstall, then choose More > Uninstall.

Please take note that not all apps can currently be removed from the Settings app.

Follow the uninstall instructions found in the Control Panel if you need assistance removing these apps.

  • Remove from the Control Panel

Enter Control Panel in the taskbar search box and choose it from the list of results.

program > programs and features.

Then choose to Uninstall or Uninstall/Change by pressing and holding (or right-clicking) on the software you wish to uninstall. then adhere to the on-screen instructions.

To learn more about Program click here:

brainly.com/question/24440921

#SPJ4

5 0
1 year ago
Please I need help.
fredd [130]

Answer:

The answer is the "TO address"

Explanation:

i just took the test and got it right sooooooo

4 0
3 years ago
A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output i
Oksi-84 [34.3K]

Answer:

Follows are the code to the given question:

def steps_to_miles(user_steps):#defining a method steps_to_miles that takes a variable user_steps

   return user_steps/2000#use return to calculate the steps

user_steps = int(input())#defining a variable user_steps that holds value from the user-end

print('%0.2f' % steps_to_miles(user_steps))#defining print that calls the steps_to_miles method

Output:

5345

2.67

Explanation:

In this code a method "steps_to_miles" that takes "user_steps" in the parameter inside the method a return keyword is used that calculates the user steps and return its values.

Outside the method, a "user_steps" variable is declared that inputs the value from the user-end pass into the method and prints its value.

3 0
3 years ago
A(n) _____ is a fake online persona created to promote a particular point of view, often in praise of a firm, product, or indivi
drek231 [11]

Answer:

<u>Sock puppet</u>

Explanation:

A sock puppet, a reference to a puppet created by placing a sock over one's hand, is a misleading or fake online identity created to promote a particular point of view, often in praise of a firm, organization, product, or individual; to manipulate public opinion or to argue, bully or review products. Regardless of the purpose it was created for, sock puppets are rarely welcome in online communities and forums.

4 0
3 years ago
Write a program that reads three numbers and print the largest one step by step answer
const2013 [10]

Answer:

CLS

INPUT"Enter any three numbers";a,b,c

IF a>b AND a>c THEN

PRINT a;"is the greatest"

ELSEIF b>a AND b>c THEN

PRINT b;"is the greatest"

ELSE

PRINT c;"is the greatest"

ENDIF

END

6 0
2 years ago
Other questions:
  • Harry is creating a presentation for a school event. He has to deliver the presentation to a huge audience. What should he keep
    14·2 answers
  • Ziffcorp, an it firm, uses a technology that automatically updates the antivirus software in all the computers in the firm whene
    13·1 answer
  • You '' friend or ''like'' a page o your favorite social media page that advertises a
    10·1 answer
  • What is constructive criticism?
    5·1 answer
  • Give 2 examples of when spreadsheets are used.
    15·1 answer
  • Which of the following is the net effect of the following combination of share and NTFS permissions when the share is accessed o
    7·1 answer
  • 1. The global economy involves trading between people from different _____
    8·1 answer
  • Assume that you want two C# or C++ programs to share some data. You can write the first program so that it writes it's output to
    5·1 answer
  • Your friend has a great idea for a new app, and she shows you a document that outlines what the app will do. This document is an
    6·1 answer
  • How to transfer mysql database from one server to another
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!