2. Consider the code given below. Write a custom print function cprintf() that implements a buffer....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. Consider the code given below. Write a custom print function cprintf() that implements a buffer. The function takes a single string as input and returns nothing. All bytes in the string are buffered until the percent symbol (%) is encountered. Upon encountering that symbol, all contents of the buffer should be flushed (printed to the stdout stream) and the buffer should be reset to empty. The percent symbol should not be printed; it is only a trigger. The buffer only needs to be large enough for this example, do not worry about overflow. The newline character should be printed but should not cause a flush. #include <stdio.h> #include <stdlib.h> #include <string.h> main() { /* custom function cprintf() goes here */ cprintf("Test\n"); sleep (1); cprintf("Re%test\n"); sleep (1); cprintf("All done\n%"); } If your function works correctly, in what chronological manner should the printed text appear? (Hint: in order to implement this function, the contents of the buffer must persist through multiple calls to the function.) 2. Consider the code given below. Write a custom print function cprintf() that implements a buffer. The function takes a single string as input and returns nothing. All bytes in the string are buffered until the percent symbol (%) is encountered. Upon encountering that symbol, all contents of the buffer should be flushed (printed to the stdout stream) and the buffer should be reset to empty. The percent symbol should not be printed; it is only a trigger. The buffer only needs to be large enough for this example, do not worry about overflow. The newline character should be printed but should not cause a flush. #include <stdio.h> #include <stdlib.h> #include <string.h> main() { /* custom function cprintf() goes here */ cprintf("Test\n"); sleep (1); cprintf("Re%test\n"); sleep (1); cprintf("All done\n%"); } If your function works correctly, in what chronological manner should the printed text appear? (Hint: in order to implement this function, the contents of the buffer must persist through multiple calls to the function.)
Expert Answer:
Answer rating: 100% (QA)
Answer The custom function cprintf is given below include include include void cprintfchar str char ... View the full answer
Related Book For
Posted Date:
Students also viewed these electrical engineering questions
-
Write a function that takes an input file stream object and a 2d array as parameters and reads all the characters in the input file stream, incrementing the count in the 2d array for each letter found
-
Test Example 1 in this section used only five pairs of data from Data Set 12 in Appendix B for a 95% confidence level. Repeat Example 1 using all of the cases with heights for both the president and...
-
Write a program that displays a single character in all possible combinations of foreground and background colors (16 x 16 = 256). The colors are numbered 0 to 15, so you can use a nested loop to...
-
Four people, each with a mass of 72.4 kg, are in a car with a mass of 1 130 kg. An earthquake strikes. The driver manages to pull off the road and stop, as the vertical oscillations of the ground...
-
Salvino Figurine Manufacturing, Inc. entered into a licensing agreement with the Major League Baseball Players Association to produce stuffed animal toys, known as Bamm Bears, bearing the names of...
-
In problem, graph each rational function using transformations. G(x) = 1 + 2/(x - 3) 2
-
Do the needs for and uses of internal and consolidated ecological accounting differ? If so, how? Are the two related?
-
Given the aggression scores below for Outcome A of the sleep deprivation experiment, verify that, as suggested earlier, these mean differences shouldnt be taken seriously by testing the null...
-
Pik-Fast, a chain of convenience stores, is planning to open a new store. The activities required, their immediate predecessors, and the optimistic, most likely, and pessimistic estimates of their...
-
1. Do you believe brand personality plays a major part in decision making? Explain. 2. After evaluating Table A, which alcohol brand will Greg be most likely to purchase? 3. Using Table B and taking...
-
XYZ Inc. has $25 million in excess cash, a market capitalization of $250 million and a market value of debt of $150 million. Its cost of equity is 13% and its cost of debt is 3%. The corporate tax...
-
A turbine shaft transmits 500 kW power at 900 rpm. The permissible shear stress is 80N/mm while twist is limited to 0.5 in a length of 2.5 m. Take G = 0.8x10 N/mm, on the basis of torsional rigidity;...
-
Required Information [The following information applies to the questions displayed below.] Selected comparative financial statements of Korbin Company follow. KORBIN COMPANY Comparative Income...
-
B) Apply IDFS on the graph below assuming 'A' as the starting node and 'I' as the goal node. At which level is the goal node reached? (3 marks) H Once you upload files from your second device, click...
-
Meghan placed an automobile in service on May 19, 2023. Her basis is $35,000 for the car and she doesn't plan to claim bonus depreciation. What is the greatest allowable amount of depreciation she...
-
Paul Swanson has an opportunity to acquire a franchise from The Yogurt Place, Incorporated, to dispense frozen yogurt products under The Yogurt Place name. Mr. Swanson has assembled the following...
-
Maria A. Solo (SSN 318-01-6921) lives at 190 Glenn Drive, Grand Rapids, Michigan 49527- 2005. Maria (age 45 and single) claims her aunt Selda Ray (SSN 282-61-4011) as a dependent. Selda lives with...
-
Jax Incorporated reports the following data for its only product. The company had no beginning finished goods inventory and it uses absorption costing. $ 57.30 per unit $ 10.30 per unit $ 7.80 per...
-
Describe three elements common to a Graphical User Interface (GUI)? How do these elements make it easier for a user to interact with the computer.
-
What features of Babbage's Analytical Engine did von Neumann incorporate into his architecture? Why did it take over a century for Babbage's vision of a general-purpose, programmable computer to be...
-
Design and implement a Web page named pal.html that tests whether a word or phrase is a palindrome. Your page should allow the user to enter a word or phrase and then display a string indicating...
-
The relative co-efficient of performance of a heat engine is the ratio of (a) The theoretical COP to the actual COP (b) The actual COP to the theoretical COP (c) The theoretical COP to the ideal COP...
-
The advantage of the vapour-compression refrigeration system over the absorption refrigeration system is that (a) The charging of the refrigerant is quite simple (b) The space requirement for...
-
Pick out the correct relation between the \(\mathrm{COP}\) of a refrigerator \(\left(\mathrm{COP}_{\mathrm{R}} ight)\) and that of the heat pump \(\left(\mathrm{COP}_{\mathrm{HP}} ight)\) (a)...
Study smarter with the SolutionInn App