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 only iostream and fstream header files.
please answer this
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education