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...
-
Based on the information provided, determine Vogls net exposure to each foreign currency in dollars.
-
Sunny Valley Inc. purchased an Internet domain name by issuing a $220,000, five-year, non-interest-bearing note to Ti-Mine Corp. with an effective yield of 12%. The note is repayable in five annual...
-
Adaris Group, headquartered in the UK, owns a 70 percent interest in Adaris Malaysia. The acquisition cost was 200 million. At the date of acquisition, 1 January 2012, Adaris Malaysia's book value...
-
Union Planters is a Tennessee bank holding company (that is, a corporation that owns banks). (Union Planters is now part of Regions Bank.) Union Planters manages $32 billion in assets, the largest of...
-
A firm is considering a new seven-year expansion project with aninitial fixed asset investment of $3.9 million. The fixed assetwill be depreciated straight-line to zero over its seven-year taxlife, 2...
-
An alphabetical list of the adjusted trial balance accounts for North Country Rentals after its first year of operations ending March 31, 2020, is shown below: Required 1. Calculate the capital...
-
Draw the output of the following systems - 15 kHz M() 1 15 kHz f kHz 0 m(1) 2 cos 30,000RI g(t) 1 (a) Low-pass filter 0-15 kHz For the signal g(t) and x(t), find the component of g(t) contained in...
-
Thomas Burberry is credited with investing gabardine fabric in the 1850s. The Burberry trademark is registered in more than ninety(90) countries around the world, and the companys signature plaid...
-
On March 10, Fat Tires Ltd. borrowed $7000.00 with an interest rate of 8.1%. The loan was repaid in full on October 13, with payments of $2900.00 on April 7 and $3500.00 on June 5. What was the final...
-
Find the domain of the function. -3 f(x) = log(+34) Write your answer as an interval or union of intervals. Domain: (0,0) (0,0) (0,0)
-
Use the X-POSITION vs. TIME graph below to answer the following questions. Express all answers in the appropriate mks units. POSITION vs. TIME GRAPH x-position (m) 6 4 2 0 -2 -4 2 4 6 8 10 t(s) A.)...
-
Suppose Tom is 25 years old and he would like to retire at age 60. Tom decides to make regular monthly deposits to an account earning an interest rate of 2% compounded monthly. a) (8 pts) He would...
-
Textbook Title: The Human Services Internship: Getting the Most from Your Experience, Edition #: 4, Author: P.M. Kiser, Publisher: Cengage Learning, Year: 2016, ISBN: 9781305537484 Part One Com....
-
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...
-
What are some typical consumer complaints?
-
What are five methods of resolving consumer complaints?
-
Marta loves shopping for holiday gifts for her friends and family. This year she started looking for gifts early, in June. She hopes that the extra time will allow her to find the perfect gift for...
Study smarter with the SolutionInn App