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
Write a calculator program that will allow only addition, subtraction, multiplication &amp; division. Have the
ozzi

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

operation = input("Which operation are you performing? (a/s/m/d) ")

if operation == "a":

   print("{} + {} = {}".format(num1, num2, num1+num2))

elif operation == "s":

   print("{} - {} = {}".format(num1, num2, num1-num2))

elif operation == "m":

   print("{} * {} = {}".format(num1, num2, num1*num2))

elif operation == "d":

   print("{} / {} = {}".format(num1, num2, num1/num2))

I hope this helps!

8 0
2 years ago
These are statements given by witnesses under oath? A. Testimony B. Admissible Evidence C. Indirect Evidence D. Circumstantial E
Aneli [31]

Answer:A. Testimony

Explanation:when someone knows something about what happened in the case held in court or they had witnessed what happened; In order to actual testify on what they know they are called on the stand and they have to raise their hand as a sign to swear an oath before the can give their testimony in court.

8 0
2 years ago
A cloud implementation engineer successfully created a new VM. However, the engineer notices the new VM is not accessible from a
Rina8888 [55]

Answer:

Option A.

Explanation:

Incorrect subnet is the most likely problem in this scenario.

4 0
3 years ago
Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
Neko [114]
The third one probably
5 0
3 years ago
Which of these characteristics is most important to a systems analyst? (1 point) (Points : 1.5) communicator
zvonat [6]

Answer: Problem solver

Explanation:

 Problem solver is the most important characteristics for the system analyst as it important for the organization to control all the problems.

System analysis basically define the problem in the particular organization to be solved and also provide the proper architecture in the system.  

The good and strong problem solving ability makes the organization more efficient in the decision making problem and also improve the overall system analyst in the organization.

7 0
3 years ago
Other questions:
  • Test if a password entered is correct. The secret phrase is Ada Lovelace. Sample Run 1 Enter the Password: Ada Lovelace Sample O
    13·1 answer
  • Microsoft Xbox operating system provides Xbox programmers with a set of common standards to use to access controllers, the Kinec
    6·1 answer
  • WILL UPVOTE NEED ANSWERS ASAP i have till 4:30
    12·1 answer
  • Which one of the following will not be considered as a microcomputer?
    12·2 answers
  • Instructions written in code that a computer follows are called:
    14·1 answer
  • Joe always misspelled the word calendar what function corrects the word
    12·2 answers
  • i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
    8·1 answer
  • What is technology? *
    10·1 answer
  • Answer this crossword for brainliest and 15 points
    9·1 answer
  • Please help ASAP! will mark brianliest! 30 points!
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!