EXERCISE - INDIVIDUAL: Create a Binary File Write a C program, create_binary_file, which takes at least...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
EXERCISE - INDIVIDUAL: Create a Binary File Write a C program, create_binary_file, which takes at least one argument: a filename, and subsequently, integers in the range 0...255 inclusive specifying byte values. It should create a file of the specified name, containing the specified bytes. For example: $ ./create_binary_file hello.txt 72 101 108 108 111 33 10 $cat hello.txt Hello! $ ./create_binary_file count.binary 1 2 3 251 252 253 254 255 $ ./print_bytes count. binary byte 1 0x01 byte 1: 2 0x02 byte 2: 3 0x03 byte 3: 251 Oxfb byte 4: 252 0xfc byte 5: 253 0xfd byte 6: 254 Oxfe byte 7: 255 0xff $ ./create_binary_file 4_bytes.binary 222 173 190 239 $ ./print_bytes 4_bytes.binary 0: 222 Oxde 1: 173 Oxad 2: 190 Oxbe 3: 239 Oxef byte byte byte byte Your program should print a suitable error message if given the wrong number of arguments, or if the file can not be created. HINT: Use fopen(3) to create the file and fputc(3) to output to the file. If you need some help starting off, read this example program to see how to use these functions to create and write to a file. HINT: For this exercise, you can use the simple function atoi(3) to convert a null-terminated string to an int. In general, strtol(3) is a more useful function because it allows error handling - but this is not required for this exercise. EXERCISE - INDIVIDUAL: Create a Binary File Write a C program, create_binary_file, which takes at least one argument: a filename, and subsequently, integers in the range 0...255 inclusive specifying byte values. It should create a file of the specified name, containing the specified bytes. For example: $ ./create_binary_file hello.txt 72 101 108 108 111 33 10 $cat hello.txt Hello! $ ./create_binary_file count.binary 1 2 3 251 252 253 254 255 $ ./print_bytes count. binary byte 1 0x01 byte 1: 2 0x02 byte 2: 3 0x03 byte 3: 251 Oxfb byte 4: 252 0xfc byte 5: 253 0xfd byte 6: 254 Oxfe byte 7: 255 0xff $ ./create_binary_file 4_bytes.binary 222 173 190 239 $ ./print_bytes 4_bytes.binary 0: 222 Oxde 1: 173 Oxad 2: 190 Oxbe 3: 239 Oxef byte byte byte byte Your program should print a suitable error message if given the wrong number of arguments, or if the file can not be created. HINT: Use fopen(3) to create the file and fputc(3) to output to the file. If you need some help starting off, read this example program to see how to use these functions to create and write to a file. HINT: For this exercise, you can use the simple function atoi(3) to convert a null-terminated string to an int. In general, strtol(3) is a more useful function because it allows error handling - but this is not required for this exercise.
Expert Answer:
Related Book For
Financial Accounting
ISBN: 978-0078025549
3rd edition
Authors: J. David Spiceland, Wayne Thomas, Don Herrmann
Posted Date:
Students also viewed these electrical engineering questions
-
Provide at least one argument against the trend toward convergence between U.S. GAAP and IFRS.
-
Describe an algorithm that, given n integers in the range 0 to k, preprocesses its input and then answers any query about how many of the n integers fall into a range [a b] in O (1) time. Your...
-
Use Excel to generate 1,000 random integers in the range 1 through 5. (a) What are the expected mean and standard deviation? (b) Show the Excel formula you used.
-
Write a program for setting three bits of an unsigned char to 1. The function set 3bits should have four parameters: the unsigned char to be changed and the three bits which are to be set to 1. For...
-
A company that is considering adding a new product line has determined that the first cost would be $80 million. The company is not sure about how the product will be received, so it has projected...
-
Visit Ally Banks YouTube channel. After reviewing video clips of Allys past advertising campaigns, how would you describe its brand image?
-
Use the data in Exercise 23 in Section 13.1 for the following. a. Compute a point estimate for the mean noise level for streets with a mean speed of 35 kilometers per hour. b. Construct a 99%...
-
A firm implementing a diversification strategy has just acquired what it claims is a strategically related target firm but announces that it is not going to change this recently acquired firm in any...
-
15) Solve by graphing in the graphing calculator (use intersect feature) a) In x = (x 1) - b) In x = x + 2-3
-
Lets return to the model of financial aid awards at a liberal arts college that was first introduced in Section 2.2. In that section, we estimated the following equation (standard errors in...
-
c) Give the example of two matrices A and B of order 2 x 2 such that AB is not equal to BA. d) Find the adjoint of the matrix A = [23]
-
Find a matrix A that induces the transformation T:R?R3 given below. 9x+y X 4x+7y -9x+5y]
-
Lucy and Zehmer are sitting in the bar of the Zehmer's restaurant, the Olde Virginnie, in Kopperl, Texas. Lucy offers $500,000 for a piece of property that Zehmer owns called the "Ferguson Farm."...
-
What mechanisms, according to functionalist theory, are in place to ensure social stability, and how might these mechanisms be challenged or undermined by rapid technological advancements and...
-
13 Done At the instant when a helicopter is 2900 feet above the surface (of a lake) it measures the angle of depression of a boat to be 48. How far is the boat from the point on the surface directly...
-
In 2021 Rosita Bloom, a well renowned Sydney based horticulturist, completed a bachelor of cooking and empanada making at the Covetous Austro-Latin Cooking Academy. As part of her degree, she wrote a...
-
1. Code the Rock Paper Scissors program: Get a move choice from playerA which must be R, P, S or r, p, s Loop until you get a valid move b. Get a move choice from player in the same manner c. Display...
-
Cobb Manufacturing Company uses a process cost system and average costing. The following production data is for the month of June 2011. Production Costs Work in process, beginning of the month:...
-
Match each of the components of relevance with its definition. Relevance 1. _________ Confirmatory value 2. _________ Predictive value 3. _________ Materiality Definitions a. Information is useful in...
-
Below is the complete list of accounts of Cobras Incorporated and the related balance at the end of March. All accounts have their normal debit or credit balance. Supplies, $1,000; Buildings,...
-
The following information relates to the intangible assets of University Testing Services (UTS): a. On January 1, 2015, UTS completed the purchase of Heinrich Corporation for $ 3,510,000 in cash. The...
-
Steam flows steadily and isentropically through a nozzle. At an upstream section where the speed is negligible, the temperature and pressure are \(450^{\circ} \mathrm{C}\) and \(6 \mathrm{MPa}\)...
-
Space debris impact is a real concern for spacecraft. If a piece of space debris were to create a hole of \(0.001 \mathrm{in} .^{2}\) area in the hull of the International Space Station (ISS), at...
-
Oxygen discharges from a tank through a convergent nozzle. The temperature and velocity in the jet are \(-20^{\circ} \mathrm{C}\) and \(270 \mathrm{~m} / \mathrm{s}\), respectively. What is the...
Study smarter with the SolutionInn App