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...
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- A criticism of the break and continue statements is that each is unstructured. These statements can always be replaced by structured statements. Describe in general how you’d remove any break statement from a loop in a program and replace it with some structured equivalent. [Hint: The break statement leaves a loop from within the body ofthe loop. Another way to leave is by failing the loop-continuation test. Consider using in theloop-continuation test a second test that indicates “early exit because of a ‘break’ condition.”] Use the technique you developed here to remove the break statement from the program of Fig. 5.13.arrow_forwardA loc-cs.org/~chu/DataStructures/H 19 Special Hint for Taking User's Input import java.util.Scanner; /** * This is an example to show you that * the method nextInt() only flushes the number to the variable * and leave the "END OF LINE" symbol in the input buffer. * If you have next input looking for "END OF LINE", the system will not wait for user's input and just take the "END OF LINE" symbol from input buffer. * So, the solution is flush "END OF LINE" out before you 大 * expect an input from user. * @author Valerie Chu * @version August 24, 2020 */ public class Example { public static void main(String[] args) { Scanner input = new Scanner (System.in); String [] item = new String[2]; int (] num = new int[2]; for (int i=0; i<2; i++) { System.out.println("Which item are you shopping for?"); item[i] = input.nextLine(); System.out.printf("How many \"%s\" do you need?\n", item[i]); num[i] = input.nextInt(); input.nextLine(); //Flush the "END OF LINE" symbol out…arrow_forwardUsing a csv file attached , Create a program on python that use the csv file. The program should accept a user's input of a compound. It should output the molar mass (in 2 decimal places only) of the compound.by using the csv file to compute for the atomic mass at name of the elements. Furthermore, if the "elements involved" are wrong an invallid message should be outputted and only existing chemical symbols are the output. The same goes for wrong input of the "number of atoms" wherein a wrong an invallid message should be outputted and only integers are to be inputted by the user. Program should look like this: Enter compound: C6H12O6 Enter elements involved: C,H,O Enter no. of Carbon atoms: AA Enter no. of Hydrogen atoms: 12 Enter no. of Oxygen atoms: 6 Wrong input of number of atoms! Try again. or Enter compound: C6H12O6 Enter elements involved: C,H,O Enter no. of Carbon atoms: 6 Enter no. of Hydrogen atoms: 12 Enter no. of Oxygen atoms: 6 Molar mass of C6H1206 is 180.16…arrow_forward
- Write a program that converts an ASCII text string from memory into all lowercase and stores the output to memory. The input string can contain uppercase and lowercase letters as well as spaces, punctuation (period, comma, question mark, exclamation point), and decimal digits. The input string will be null-terminated (that is, end with a 0 byte) and the output string is also to be null-terminated. (Observe: a 0 byte is different than the ASCII code for decimal digit 0 , which is 0x30.) Example: Convert the string "IN 2023, faLL stARTs on September 23." to "in 2023, fall starts on september 23.".arrow_forwardI need the answer as soon as possiblearrow_forwardWrite a Matlab program in a script file that finds and displays all the numbers between 700 and 2999, whose product of digits is 6 times the sum of the digits (e.g. 2864 since 2*8*6*4 = 6(2+8+6+4)). You may use a loop in the script. For extra credit, print out also the number of times that the product and sum were the same! (5 pts)arrow_forward
- Please note that the input should be taken from a txt file you can create one with the information provided in the sample input and the output should be written in another txt file. Use python to solve this problem. Please answer as instructed.arrow_forwardModify the program I created in the first picture for the question 1)arrow_forwardUsing Functions and Containers, create a program in python that accepts a sequencce of doublee-stranded DNA. The program should cleave the DNA strand using the restriction enzyme EcoRI and should output the resulting sequences. It should be noted that The EcoRI specifically cleaves the palindromic sequence GAATTC. Output should be like this: Enter Leading Strand: GGTCAGAATTCGCTGAEnter Lagging Strand: CCAGTCTTAAGCGACT The Resultitng Sequences: Leading strand: GGTCAG, AATTCGCTGA Lagging strand: CCAGTCTTAA, GCGACTarrow_forward
- Write full program on the emulator , run it and copy the output in this file .. Then send it to me. (Screenshot) … mov bx, offset num1 ; point bx to first number mov cx, 10 ; load numbers count add ax, [bx] ; add number pointed by bx to ax l1: add bx, 2 sub cx, 1 jnz l1 mov [num1+20], ax ; write back resultarrow_forwardConvert the following C code to LCC2K (you should replicate the control flow as best you can... a trivial solution to this would be to load the final answer, but that's not the point of this exercise) EDIT: There was intended to be a "count-" in the loop, but you can either include it or leave it as is. When converting to assembly, we generally don't worry about whether the original code is valid, we just replicate the logic. int count = 10; int i=0; while (count > 0) { i « 1; } Your code should contain 20 lines of assembly or fewer. The final value of i can be stored in any register. You should make use of the .fill directives below. neg1 .fill -1 ten .fill 10arrow_forwardWrite a program that will sequentially list numbers from 0 to 50, changing its color depending on the size of the number, for example, for numbers from 0 to 10 it will be green, 11 to 22 red and 23 to 35 blue, etc. Limit the screen output speed to about 1 character / second. In order to change colors, you must first use the GetStdHandle function to get a handle to the console, which is similar to getting a file pointer before working with a file. It is done e.g. as follows: HANDLE hConsole; hConsole = GetStdHandle (STD_OUTPUT_HANDLE); The above functions are defined in windows.h Tip 2: Write a utility to find out the colors corresponding to all combinations from 0 to 255. Tip 3: Instructions and sample program for working with time. C language plz with explanation of codes. thanksarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education