A certain file foo contains the ASCII text string This file contains 28 bytes.. That is,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A certain file foo contains the ASCII text string "This file contains 28 bytes.". That is, the bytes of the file, viewed as 8-bit integers, contain the values 0x54, 0x65, 0x73, 0x74, and 0x20, etc. a. Suppose a program opens foo for reading and writing (file descriptor fd is returned), and then does the following. Assume buf is a 30-byte array of char. if ((rv = read (fd, buf, 10)) < 0) {...handle error... } if ((rv = write(fd, buf, 10)) < 0) {... handle error... } Assuming both calls return 10, what does the file contain after this code runs? b. Suppose the same program next calls 1seek (fd, 0, SEEK_SET) to "rewind" the file offset to the beginning, and then does the following: if ((rv = read (fd, buf, 30)) < 0) {...handle error... } strcpy (buf, "That"); if ((rv = write(fd, buf, rv)) < 0) {... handle error... } What does the file now contain? A certain file foo contains the ASCII text string "This file contains 28 bytes.". That is, the bytes of the file, viewed as 8-bit integers, contain the values 0x54, 0x65, 0x73, 0x74, and 0x20, etc. a. Suppose a program opens foo for reading and writing (file descriptor fd is returned), and then does the following. Assume buf is a 30-byte array of char. if ((rv = read (fd, buf, 10)) < 0) {...handle error... } if ((rv = write(fd, buf, 10)) < 0) {... handle error... } Assuming both calls return 10, what does the file contain after this code runs? b. Suppose the same program next calls 1seek (fd, 0, SEEK_SET) to "rewind" the file offset to the beginning, and then does the following: if ((rv = read (fd, buf, 30)) < 0) {...handle error... } strcpy (buf, "That"); if ((rv = write(fd, buf, rv)) < 0) {... handle error... } What does the file now contain?
Expert Answer:
Answer rating: 100% (QA)
a Suppose a program opens foo for reading and writing file descriptor fd is returned and then does t... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
What type of isomers are exhibited by [Fe(en) 3 ]Cl 2 (en = ethane-1,2-diamine)? no isomers are possible. cis and trans isomers fac and mer isomers optical isomers
-
A radioactive nucleus at rest decays into a second nucleus, and electron, and a neutrino. The electron and neutrino are emitted at right angles and have moment a of 9.30 x 10-23 kg m/s and 5.40 x...
-
As a community service, disc jockeys from radio station WMKT formed a basketball team to help raise money for local nonprofit organizations. The host organization finds or fields a competing team and...
-
What are the three parts of a make rule?
-
David James is a cost accountant and business analyst for Doorknob Design Company (DDC), which manufactures expensive brass doorknobs. DDC uses two direct cost categories: direct materials and direct...
-
Multiple Choice Question One indication of financial weakness is that Multiple choice question. the fair value of the firm's debt is higher than the book value. current cash from operations is more...
-
Managers often assume a strictly linear relationship between cost and the level of activity. Under what conditions would this be a valid or invalid assumption?
-
Listed below are amounts of arsenic in samples of brown rice from three different states. The amounts are in micrograms of arsenic and all samples have the same serving size. The data are from the...
-
The human eye can detect light at a frequency of 7.56x10 Hz in the visible region of the spectrum. Calculate the energy, in joules, of an individual photon of this light.
-
Suppose you go out for a walk. You walk straight ahead for 100 meters. Then you turn to your left and walk for another 50 meters. Finally you turn to your right and walk another 25 meters. How far...
-
Summarize either how we see color, how we hear music, what music is , how earthquake waves travel, or how a particular optical phenomenon or instrument we have discussed works.
-
What is a device control block (DCB), and how is it used in device management
-
I. Efficient Two Asset Portfolios Assume that the expected return on asset 1 is 5% and the expected return on asset 2 is 4%. The standard deviation of asset 1 is 3.0% and 1.5% for asset 2. Assume the...
-
If a person uses an average of 2.5 gallons of water every 45 seconds in a city X. How many cubic meters are required per day and per year, if it has a population of 123456 inhabitants.
-
QUESTION 2 The CEO of Farisha Hijab Sdn Bhd insisted on further investigation to be carried out that he also required Mr Muaz to conduct the analysis of variance for the material and labour of the...
-
Write a program similar to the one in Listing 10.10 that can write an arbitrary number of Species objects to a binary file. (Species appears in Listing 5.19 of Chapter 5.) Read the file name and the...
-
Imagine a program that compresses files by 80 percent and stores them on storage media. Before the compressed file is stored, it must be divided into blocks of 512 bytes each. Develop an algorithm...
-
What would the following statements, when used in a Java program, display on the screen? int age; age = 20; System.out.println ("My age is"); System.out.println(age);
-
Which of the following statements about Islamic banking is not true? a. Interest (known as Riba) is prohibited. b. Conventional interest is considered by scholars to result in inequality and...
-
Which of the following statements is true? a. Murabaha, an equity instrument, is a sales contract in which the asset is sold by the bank to the customer at costplus- profit. b. Salam is a forward...
-
The relationship between an Islamic bank and its customers is that of a: a. Partner/investor b. Buyer and seller c. Lessor/lessee d. All of the above
Study smarter with the SolutionInn App