printf - PRINTF(3) Linux Programmer’s Manual PRINTF(3)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
PRINTF(3) Linux Programmer’sManual PRINTF(3) NAME printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - formatted output conversion SYNOPSIS #include <stdio.h> int printf(const char * format ,...); int fprintf(FILE * stream ,const char * format ,...); int sprintf(char * str ,const char * format ,...); int snprintf(char * str ,size_t size ,const char * format ,...); #include <stdarg.h> int vprintf(const char * format ,va_list ap ); int vfprintf(FILE * stream ,const char * format ,va_list ap ); int vsprintf(char * str ,const char * format ,va_list ap ); int vsnprintf(char * str ,size_t size ,const char * format ,va_list ap ); DESCRIPTION The functions in the printf family produce output according to a format as described below. The functions printf and vprintf write output to stdout ,the standard output stream; fprintf and vfprintf write output to the givenoutput stream ; sprintf , snprintf , vsprintf and vsnprintf write to the character string str . The functions vprintf , vfprintf , vsprintf , vsnprintf are equivalent to the functions printf , fprintf , sprintf , snprintf ,respectively ,except that theyare called with a va_list instead of a variable number of arguments. These functions do not call the va_end macro. Consequently ,the value of ap is undefined after the call. The application should call va_end(ap) itself afterwards. These eight functions write the output under the control of a format string that specifies howsubsequent arguments (or arguments accessed via the variable-length argument facilities of stdarg (3)) are converted for output. Returnvalue These functions return the number of characters printed (not including the trailing ‘\0’ used to end output to strings). snprintf and vsnprintf do not write more than size bytes (including the trailing ’\0’), and return -1 if the output was truncated due to this limit. (Thus until glibc 2.0.6. Since glibc 2.1 these functions fol- lowthe C99 standard and return the number of characters (excluding the trailing ’\0’) which would have been written to the final string if enough space had been available.) Format of the format string The format string is a character string, beginning and ending in its initial shift state, if any. The format string is composed of zero or more directives: ordinary characters (not % ), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character % ,and ends with a conversion specifier .Inbetween there may be (in this order) zero or more flags ,anoptional minimum field width ,an optional precision and an optional length modifier
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2009 for the course COMP 2510 taught by Professor A during the Spring '06 term at BC.

Page1 / 6

printf - PRINTF(3) Linux Programmer’s Manual PRINTF(3)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online