Question

In: Computer Science

I try to invent the examples, but I can't still. I do not understand how setvbuf...

I try to invent the examples, but I can't still.
I do not understand how setvbuf can be useful, and also I don't understand with setbuf. please explain setvbuf vs setoff

Solutions

Expert Solution

setbuf( ): This function associates with the buffer with the specified stream. setbuf() will let us change the way,how a stream will buffered , & to control the size and location of the buffer.
void setbuf( FILE *fp, char *buffer );
Here,
Fp:
The stream that we want to associate with a buffer.
Buffer:
NULL, or a pointer to the buffer.
Here, the parameter stream is the pointer of stream file, and the BUF is the initial address of the buffer.
When, buffer argument is NULL, the stream is unbuffered. When ,Buffer parameter is not null character pointer, then the array it points to is used for the buffering.
setbuf() is also implement the ability to manipulate the flow of file directly when manipulating the buffer.
setbuf() function only works with ILE C when we using the integrated file system. Stream pointer must
refer to the open file before any I/O has been done.
Example : set the buffer that will stream use.
int main ()
{
char buffer[BUFSIZ];
FILE *fp1, *fp2;

fp1=fopen ("check.txt","A"); //open file
fp2=fopen ("find.txt","B");

setbuf ( fp1 , buffer ); // controlling buffering
fputs ("File will sent to buffered stream",fp1);
fflush (fp1); // write buffer to file

setbuf ( fp2 , NULL ); // controlling buffering
fputs ("File will sent to unbuffered stream",fp2);

//Set buf to null to turning off the buffering.
//BUFSIZ is defined in the <stdio.h>.
fclose (fp1); //close stream
fclose (fp2);
return 0;

}

The setvbuf() is more capable than setbuf().
Setvbuf() will assign the buffering to a stream.
setvbuf () is used to set the buffer for a file stream, and it’s prototype :
int setvbuf ( FILE * stream, char * buf, int type/ mode, size_t size );
Here, the parameter “stream” is a pointer to file stream, & “buf” is the buffer's first address, “type” is the type of buffer, & the “size” is the number of bytes in the buffer.
setvbuf() function can be used on any open stream to change its buffer.
#include <stdio.h>

int main ()
{
FILE *pFile;

pFile=fopen ("search.txt","s"); // open file

setvbuf ( pFile , NULL , _IOFBF , 1024 ); // buffer of 1024 bytes is requested for the stream
// Specifies a buffer for the stream
// File operations

fclose (pFile); // close the file

return 0;
}
_IOFBF   Full buffering: On output, data written once the buffer is full.
_IOLBF   Line buffering: On output, data is written when a newline character is inserted into the stream _IONBF   No buffering: No buffer will used. I/O operation written as soon as possible.


Related Solutions

please explain milio's framework for prevention i can't understand it
please explain milio's framework for prevention i can't understand it
how to calculate MACRS Depreciation. Please describe Clearly with example calculation, i can't understand by old...
how to calculate MACRS Depreciation. Please describe Clearly with example calculation, i can't understand by old answers.
Please use EXCEL to answer and show all formulas. I can't understand the answer if I...
Please use EXCEL to answer and show all formulas. I can't understand the answer if I can't see the formulas for each field. Thank you very much. Newman manufacturing is considering a cash purchase of the stock of Grips Tool. During the year just​ completed, Grips earned $4.25 per share and paid cash dividends of ​$2.55 per share ​(D0=$2.55). Grips' earnings and dividends are expected to grow at 25​% per year for the next 3​ years, after which they are...
I can't understand the difference between 'the work the electric force does' and 'the work the...
I can't understand the difference between 'the work the electric force does' and 'the work the electric field does'. Could you explain it in detail?
I can't really understand why two higgs doublets are required in SUSY. From the literature, I...
I can't really understand why two higgs doublets are required in SUSY. From the literature, I have found opaque explanations that say something along the lines of: the superpotential W must be a holomorphic function of the chiral supermutiplets and thus we need to introduce another chiral supermutiplet. I also know that this is somehow related to an anomaly cancellation. Can somebody help to make this a bit more clear?
I need to solve math problem by using freemat or mathlab program. However, I can't understand...
I need to solve math problem by using freemat or mathlab program. However, I can't understand how to make a code it. This is one example for code ( freemat ) format long f = @(x) (x^2) % define f(x) = x^2 a=0 b=1 N=23 dx = (b-a)/N % dx = delta_x 1. Methods: (a) Left Rectangular Rule also known as Lower sum. (b) Right Rectangular Rule also know as upper sum. (c) Midpoint Rule (d) Trapezoid Rule (e) Simpson...
I am supposed to map out the following and can't figure out how to do it!...
I am supposed to map out the following and can't figure out how to do it! Can somebody help? The experiment has to do with determining the simplest formula of potassium chlorate and to determine the original amount of potassium chlorate in a potassium chlorate-potassium chloride mixture by measuring the oxygen lost from decomposition. The chemical reaction is 2KClO3(s) ------> 2KCL(s) + 3 O2(g) I am supposed to map out 1. Mass of oxygen lost in the first part 2....
Can someone please explain how to calculate this? I truely do not understand how to do...
Can someone please explain how to calculate this? I truely do not understand how to do theoretical yield... calculate theoretical yield and percent yield for anthracene-9-methylmalemide and N-methylmalemide in water amounts used were 0.070 g of anthracene-9-methanol and 50 mL of water and 0.103 g of N-methylmaleimide. the weight of the product was 0.043 g
(i) How do you understand volatility? (ii) How do we forecast volatility?
(i) How do you understand volatility? (ii) How do we forecast volatility?
I do not understand how you post it. When I put some of the answers in,...
I do not understand how you post it. When I put some of the answers in, they are wrong. Comprehensive Problem 5 Part B: Note: This section is a continuation from Part A of the comprehensive problem. Be sure you have completed Part A before attempting Part B. You may have to refer back to data presented in Part A and use answers from Part A when completing this section. Genuine Spice Inc. began operations on January 1 of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT