Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 10, Problem 10.10HW

Explanation of Solution

Modified code from figure 10.5:

The modified code for “cpfile.c” is shown below:

//Include header file

#include <stdio.h>

#include "csapp.h"

//Main function

int main(int argc, char* argv[])

{

  //Declare "int" variable

  int n;

  //Create the object for read buffer of type

  rio_t rio;

  //Declare "MAXLINE" for memory

  char buf[MAXLINE];

/* Check the command line arguments. If the command line contains two argument, then copy the infile to standard output */

  if (argc == 2)

  {

    /* Store the descriptor number in "fd" */

    int fd = Open(argv[1], O_RDONLY, 0);

    while ((n = Rio_readn(fd, buf, MAXBUF)) != 0)

      Rio_writen(STDOUT_FILENO, buf, n);

    //Exit the process

    exit(0);

  }

/* Otherwise copy a text file from standard input to...

Blurred answer
Students have asked these similar questions
Use the cubicSpline module to write programs that interpolate between a given data point with a cubic spline. The program must be able to evaluate the interpolant for more than one x value. As a test, use the data points specified in the previous Example and calculate the interpolants at x = 1.5 and x = 4.5 (due to symmetry, these values must be the same) import numpy as np from cubicSpline import * xData = np.array([1,2,3,4,5], float) yData = np.array([0,1,0,1,0], float) k = curvatures (xData, yData) while True: try: x = eval(input("\nx ==> ")) except SyntaxError: break print("y=", evalSpline (xData, yData, k, x)) input ("Done. Press return to exit") Exercise Fix the Cubic Spline Program There is an error in the Cubic Spline program, fix it and evaluate the values of x 1/2 = 1.5 and x = 4.5, where the results of both values must be the same.
Modify the below program that the input values representingfractions are stored with denominators that are positive integers. You cannot require the user to only enter a positive denominator value; the user should not be inconvenienced by such a restriction. For example, whilst values of 1 / -2 are acceptable inputs for a fraction, the output representation should be -1 / 2. Your solution should check the denominator input; if it is negative, swap the sign of both numerator and denominator instance variables.    //Import the essential package import java.util.ArrayList; import java.util.Scanner; //Define the class Fraction class Fraction {         private int n, d;       public Fraction()     {         //Initialize the values         this.n = this.d = 0;     }     public Fraction(int n, int d)     {         //Initialize the variables         this.n = n;         this.d = d;     }     //Define the getter function getNum() that returns the numerator     public int getNum()     {…
Consider the following common task done repeatedly:• Read the next input (x = read())• If the input is not valid (valid(x)), exit the loop• Print the input read (print(x))• Repeat the loop Using C++ syntax:Write the loop above using a pretest loop, posttest loop and a user-located loop control mechanisms. Which one is more readable? Why?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning