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)
- Write a program, sonar.c, compiled with GCC on the RPi 3b/3b+, that performs the following steps using the provided sysfs_gpio files: a. Include the sysfs_gpio.h file b. Initializes the TRIGGER pin to be an output by calling gpioOutput() c. Initializes the ECHO pin to be an input by calling gpioInput() d. Sets Trig signal high (1) and then low (0) e. Zero a count variable f. Enter a while loop that waits until the Echo signal goes high There is no code in the while loop g. The program exits the first loop h. Enter another while loop that waits until the Echo signal goes low The while loop contains code that increments the count variable i. The program exits the second loop j. The count value is now proportional to the distance traveled k. Print the raw count value l. Convert the value to a distance (cm) by empirical means (the desk is about 4 feet or 122 cm in length) sysfs_gpio.c: #include…arrow_forwardWrite a function-based C++ program that reads a c-string from a file (input.txt) and an integer key from the console. Your program should encrypt the string by adding the key value to all its alphabets. Make sure that if adding the key value makes the alphabet go past the letter ‘Z’ or ‘z’, you must rollover and start over from ‘A’ or ‘a’ respectively. All other non-alphabetic characters should remain the same. Write the encrypted string into an output file (output.txt). Example 1: Input File Aliens on Earth! Enter a key: 1 Output File Bmjfot po Fbsui! Example 2: Input File Welcome to Xiwan restaurant XYZ. Enter a key: 5 Output File Bjqhtrj yt Cnbfsl wjxyfzwfsy CDE.arrow_forwardWrite a program, sonar.c, compiled with GCC on the RPi 3b/3b+, that performs the following stepsusing the provided sysfs_gpio files:a. Include the sysfs_gpio.h fileb. Initializes the TRIGGER pin to be an output by calling gpioOutput()c. Initializes the ECHO pin to be an input by calling gpioInput()d. Sets Trig signal high (1) and then low (0)e. Zero a count variablef. Enter a while loop that waits until the Echo signal goes highThere is no code in the while loopg. The program exits the first looph. Enter another while loop that waits until the Echo signal goes lowThe while loop contains code that increments the count variablei. The program exits the second loopj. The count value is now proportional to the distance traveledk. Print the raw count valuel. Convert the value to a distance (cm) by empirical means(the desk is about 4 feet or 122 cm in length) sysfs_gpio.c: #include <stdio.h>//-----------------------------------------------------------------------------//…arrow_forward
- Implement the counter increment, and branch back to the start of the loop. When you havecompleted these steps, the basic structure of the counter control loop has been implemented,and your code should look similar to the following:.text li $s0, 0 lw $s1, n start_loop: sle $t1, $s0, $s1 beqz $t1, end_loop # code block addi $s0, $s0, 1 b start_loop end_loop:.data n: .word 5arrow_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_forwardWrite a programme called pgmReduce which takes 3 arguments:1. an input file (either ASCII or binary)2. an integer factor n, and3. an output fileand reduces the input file by that factor in each dimension. For example, if the invocation is:pgmReduce inputFile 5 outputFileand inputFile is a 13x17 image, then outputFile should be a 2x3 image in which only thepixels with row and column of 0 modulo 5 in the inputFile exist.arrow_forward
- Implement a program which divides a user input by 8 using only bit shift. Your programshould include a proper and useful prompt for input, and print the results in a meaningful mannerarrow_forwardwhy you can't answer this , please try .... Write a CPP program that manages the reservation of patient for a doctorHere are some details:- The doctor is available on Sun, Mon, Tue and Wed from 10:00AM to 12:00AM he is alsoavailable on Thu from 4:00pm to 8:00pm.- Each reservation slot is 1 hour.- If the reservation slot is free, the patent will write his or her name- If the reservation is successful, the patent will receive a reservation number.- The patent can see the available free reservation slots on a given day.- The patent cannot make a reservation in a slot unless it is free.- The patent can cancel a reservation if he/she wrote the reservation number correctly.- The patent can ask about the reservation time if he/she wrote the reservation number correctly.- This program does not end.here are some scenarios:Hello, if you wish to make a reservation, please press 1. If you wish to askabout your reservation, please press 2: 2please enter your reservation number: 1221Hello Salem…arrow_forwardWhat does the following program do, assuming a set of integers are stored starting at location x4000 and MASK is used to force the program to branch somewhere?.ORIG x3000LD R0, NUMSLD R2, MASKLOOP LDR R1, R0, #0BRz DONEAND R5, R1, R2BRz LP1BRnzp NEXTLP1 ADD R1, R1, R1STR R1, R0, #0NEXT ADD R0, R0, #1BRnzp LOOPDONE HALTNUMS .FILL x4000MASK .FILL x8000.ENDa. add only positive integers.b. add only negative integers.c. doubles only the positive integers.d. doubles only the negative integers.e. None of the above.arrow_forward
- Write a new program using your LFSR function from the first problem. Start from state 0x00000001, then run a loop counting all the possible states in the LFSR before it cycles back to 0x00000001. This is shown by the following pseudocode: count = 0; initial = state = 0x00000001; do { state = LFSR(state); count++; while (state != initial); print count; Verify that the number of states is (2^15) - 1 = 32767 . Your program should complete within 30 seconds. If it takes longer then you likely have entered an infinite loop.arrow_forwardYou have been tasked to write a C++ program that will go through the first step of encrypting an input file and writing the encrypted contents to an output file.For each letter read in from the input file, add 3 letters to the value of the input letter. If the input letter is an A then the encrypted letter would be a D. If the input letter from the input file is an X then the encrypted letter would be an A. All spaces, digits, punctuation, and special characters do not need to be encrypted at this level. Simply write the space, punctuation, or special character to the output file as is. If a letter is uppercase in the input file, it should remain as an uppercase character in the output file. If a letter is lowercase in the input file, it should remain as a lowercase character in the output file.Since this program runs each month, the input file will be of various lengths; therefore, the program will read until end of file.The input file is found in the current directory and is…arrow_forwardWrite a MIPS procedure that takes as its three parameters the address of a zero-terminated string, a character c, and an integer n, and returns the number of distinct runs of consecutive instances of c in the string that are of length at least n. Also, write a simple main program to test your procedure. Your main program should input a string from the user (you may assume that the string has at most 20 characters), input the character and the integer, invoke your procedure, output the return value, and then terminate. For example, given the inputs “bbabbbbagbgbb”, “b”, and 2, the output should be 3. Your code must use the “standard” conventions covered in class for passing parameters and returning results. code in mipsarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr