Flylib.com

Books Software

 
 
 

C Programming on the IBM PC (C Programmers Reference Guide Series) - page 161

setbuf

#include <stdio.h>void setbuf(FILE *

stream

, char *

buf

);

The setbuf( ) function specifies the buffer that stream will use or, if called with buf set to null, turns off buffering. If a programmer-defined buffer is to be specified, it must be BUFSIZ characters long. BUFSIZ is defined in < stdio.h >.

In C99, stream and buf are qualified by restrict .

Related functions are fopen( ) , fclose( ) , and setvbuf ( ) .


setvbuf

#include <stdio.h>int setvbuf(FILE *

stream

, char *

buf

, int

mode

, size_t


size

);

The setvbuf( ) function allows the programmer to specify a buffer, its size, and its mode for the specified stream. The character array pointed to by buf is used as the buffer for I/O operations on stream . The size of the buffer is set by size and mode determines how buffering will be handled. If buf is null, setvbuf( ) will allocate its own buffer.

In C99, stream and buf are qualified by restrict .

The legal values of mode are _IOFBF , _IONBF , and _IOLBF . These are defined in < stdio.h >. When mode is set to _IOFBF , full buffering will take place. If mode is _IOLBF , the stream will be line buffered. For output streams, this means that the buffer will be flushed each time a newline character is written. The buffer is also flushed when full. For input streams, input is buffered until a newline is read. If mode is _IONBF , no buffering takes place.

The setvbuf( ) function returns zero on success and nonzero on failure.

A related function is setbuf ( ) .


snprintf

#include <stdio.h>int snprintf(char * restrict

buf

, size_t

num

, const char * restrict

format

, ...)

The snprintf( ) function was added by C99.

The snprintf( ) function is identical to sprintf( ) except that a maximum of num –1 characters will be stored into the array pointed to by buf . On completion, this array is null- terminated . Thus, snprintf( ) allows you to prevent buf from being overrun .

Related functions are printf( ) , sprintf( ) , and fsprintf( ) .


sprintf

#include <stdio.h>int sprintf(char *

buf

, const char *

format

, ...);

The sprintf( ) function is identical to printf( ) except that the output is put into the array pointed to by buf instead of being written to the stdout . The array pointed to by buf is null- terminated . See printf( ) .

In C99, buf and format are qualified by restrict .

The return value is equal to the number of characters actually placed into the array.

It is important to understand that sprintf( ) provides no bounds checking on the array pointed to by buf . This means that the array will be overrun if the output generated by sprintf( ) is greater than the array can hold. See snprintf ( ) for an alternative.

Related functions are printf( ) and fsprintf( ) .


sscanf

#include <stdio.h>int sscanf(const char *

buf

, const char *

format

, ...);

The sscanf( ) function is identical to scanf( ) except that data is read from the array pointed to by buf rather than stdin . See scanf( ) .

In C99, buf and format are qualified by restrict .

The return value is equal to the number of variables that were actually assigned values. This number does not include fields that were skipped through the use of the * format command modifier. A value of zero means that no fields were assigned, and EOF indicates that an error occurred prior to the first assignment.

Related functions are scanf( ) and fscanf( ) .