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...
-
In the case of The Canny Cashier, name one control that could have revealed signs of the embezzlement.
-
Determine the output of an infinite-length (p = ) m-step forward predictor and the resulting mean-square error when the input signal is a first-order autoregressive process of the form x(n) = ax(n ...
-
Identify the most appropriate approach and then design. Provide a rationale as to why this approach and design would be most appropriate. Develop a hypothetical research scenario that would...
-
Garnett Printing Corp. uses a job order cost system.The following data summarize the operations related to the first quarter??s production.1. Materials purchased on account $192,000, and factory...
-
A center that has been in operation for five years needs Group of answer choices only an operating budget for the upcoming year only a long-range financial plan that includes a 10 year projection on...
-
Soybean oil is to be pumped from a storage tank to a processing vessel. The distance is 148 m and included in the pipeline are six right-angle bends, two gate valves and one globe valve. If the...
-
RHO Company began operations on January 1 and produces a single product that sells for $10.25 per unit. The standard capacity is 80,000 units per year. Of the 80,000 units that were produced, 70,000...
-
Economy Law, 1. How to improve the employee's legal consciousness in a corporate. 2. The paper should at least discuss the rules which should be known by the employee in a corporate based on the...
-
Use the method of variation of parameters to determine a particular solution to the given equation. y''' + 15y'' +75y' + 125y = e 5x Yp(x) =
-
You also learned in Chapter 9 that directors and officers who act in breach of their fiduciary duties owed to the corporation and its shareholders can be personally liable for their actions. Can you...
-
Discuss two or three strategies you can utilize when writing or speaking to persuade others to accept your point of view. Please support your assertions using two (2) scholarly sources.
-
1. Executive Summary on BSN trauma nurse 2. What factors influence availability of jobs in BSN trauma nursing? 3. What factors affect the salary you are offered? 4. What expenses (including...
-
A W21x57 floor beam supports a 5-inch-thick reinforced concrete slab with an effective width b of 75 inches. Sufficient shear connectors are provided to make the beam fully-composite. The concrete...
-
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...
-
This chapter suggests that estimating project costs is a challenging process that can resemble an art form as much as science. Describe the different methods used to estimate costs on a project. How...
-
Consider the common problems with project cost estimation and recall a project with which you have been involved. Which of these common problems did you encounter most often? Why?
-
Explain the concept of activity-based costing. What are the steps involved in this process?
Study smarter with the SolutionInn App