OAR

RTEMS GNU Tools On-Line Library


printf

PREV UP NEXT Bookshelf

3.35: printf, fprintf, sprintf, snprintf---format output

Synopsis

#include <stdio.h>

int printf(const char *format [, arg, ...]);
int fprintf(FILE *fd, const char *format [, arg, ...]);
int sprintf(char *str, const char *format [, arg, ...]);
int snprintf(char *str, size_t size, const char *format [, arg, ...]);

Description
printf accepts a series of arguments, applies to each a format specifier from *format, and writes the formatted data to stdout, terminated with a null character. The behavior of printf is undefined if there are not enough arguments for the format. printf returns when it reaches the end of the format string. If there are more arguments than the format requires, excess arguments are ignored.

fprintf, sprintf and snprintf are identical to printf, other than the destination of the formatted output: fprintf sends the output to a specified file fd, while sprintf stores the output in the specified char array str and snprintf limits number of characters written to str to at most size (including terminating 0). For sprintf and snprintf, the behavior is also undefined if the output *str overlaps with one of the arguments. format is a pointer to a charater string containing two types of objects: ordinary characters (other than %), which are copied unchanged to the output, and conversion specifications, each of which is introduced by %. (To include % in the output, use %% in the format string.) A conversion specification has the following form:

       %[flags][width][.prec][size][type]

The fields of the conversion specification have the following meanings:


Returns
sprintf returns the number of bytes in the output string, save that the concluding NULL is not counted. printf and fprintf return the number of characters transmitted. If an error occurs, printf and fprintf return EOF. No error returns occur for sprintf.


Portability
The ANSI C standard specifies that implementations must support at least formatted output of up to 509 characters.

Supporting OS subroutines required: close, fstat, isatty, lseek, read, sbrk, write.



PREV UP NEXT Bookshelf

Packaging copyright © 1988-2000 OAR Corporation
Context copyright by each document's author. See Free Software Foundation for information.