Question

1) Using pointers and avoiding unnecessary local variables, write a function, rmchr that takes a string and a character as arguments. The rmchr function should remove all occurrences of the character from the string. The rmchr function should not leave spaces characters in the string where characters have been removed. The resulting string should be returned using an appropriate data type, not printed to the command line.
      
2) Using pointers and avoiding unnecessary local variables, write a function, rmstr that takes a 2 strings as arguments. The rmstr function should remove all occurrences of the string from the string. The rmstr function should not leave spaces characters in the string where the string has been removed. The resulting string should be returned using an appropriate data type, not printed to the command line.

3) Write a program, that copies content of one (source) file to another(destination) file. This program works by first prompting the user for the names of the source and destination files. Write the program using either the Windows or POSIXAPI, not the standard C library (ie.use the open() function, not fopen())or by using process­launching functions likesystem(). Be sure to include all necessary error checking, including ensuring that the source file exists. Once you have correctly designed and tested the program, run the program using utility that traces system calls. Linux, for example, provides the trace utility. Provide a log and report on the number and types of systems calls issued by the system as you ran your program. How many different system calls were necessary invoke during the execution of your program?

4) Write a program which monitors and records on the screen and in a report file, the alterations in the size of a given file over some amount of time (measured in minutes) passed to the program interactively. The messages regarding the changes should be displayed on the screen every 10­15 seconds during the allocated time.

(Example: Assume that the monitoring program is named monprog. It needs to accept command line arguments: monitored file name and tm equal to number of seconds. Also the file that is to be monitored and modified may have name such as flexfile. So for such a filecommand: monprog flexfile 5 means that the overall time is 5 minutes and that we are monitoring modifications of the file flexfile, displaying the amount of time passed and the present size (in bytes) of the file flexfile.

Output may be similar to this:

Seconds File size
10 453
20 453
30 532
40 112
……..

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

/**
* get size of the file
* @param file
* @return size of file
*/
long long getSize(char * file);

/*
*
*/
int main(int argc, char** argv) {

    int seconds;
    int step;
    int i;
    long long size;
   
    // test for arguments
    if (argc != 3) {
       printf("Sample input : monprog flexfile 5\n");
       return 1;
    }
   
    // get number of second
    seconds = atoi(argv[2]) * 60;
    // each step sleeps 10 seconds
    step = seconds / 10;
   
    printf("Seconds File size\n");
    seconds = 10;
    for (i = 0; i < step; i++) {
       // sleep
       sleep(10);
       size = getSize(argv[1]);
       if (size < 0) { // file not found
            printf("File cannot be reached\n");
            break;
       }
       // print the output
       printf("%6d %lld\n", seconds, size);
       seconds += 10;
    }
    return (EXIT_SUCCESS);
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$68.00

or free if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats