Estratto del documento

Fprintf: Print formatted output

The Single UNIX ® Specification, Version 2

Copyright © 1997 The Open Group

Name

fprintf, printf, snprintf, sprintf - print formatted output

SYNOPSIS

#include <stdio.h>

  • int fprintf(FILE *stream, const char *format, ...);
  • int printf(const char *format, ...);
  • int snprintf(char *s, size_t n, const char *format, ...);
  • int sprintf(char *s, const char *format, ...);

Description

The fprintf() function places output on the named output stream. The printf() function places output on the standard output stream stdout. The sprintf() function places output, followed by the null byte, '\0', in consecutive bytes starting at *s; it is the user's responsibility to ensure that enough space is available.

The snprintf() function is identical to sprintf() with the addition of the argument n, which states the size of the buffer referred to by s.

Each of these functions converts, formats, and prints its arguments under the control of the format. The format is a character string, beginning and ending in its initial shift state, if any. The format is composed of zero or more directives: ordinary characters, which are simply copied to the output stream, and conversion specifications, each of which results in the fetching of zero or more arguments. The results are undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments are evaluated but are otherwise ignored.

Conversions can be applied to the nth argument after the % in the argument list, rather than to the next unused argument. In this case, the conversion character % is replaced by the sequence %n$, where n is a decimal integer in the range [1, {NL_ARGMAX}], giving the position of the argument in the argument list. This feature provides for the definition of format strings that select arguments in an order appropriate to specific languages (see the EXAMPLES section).

In format strings containing the %n$ form of conversion specifications, numbered arguments in the argument list can be referenced from the format string as many times as required. In format strings containing the % form, each argument in the argument list is used exactly once.

All forms of the functions allow for the insertion of a language-dependent radix character in the output string. The radix character is defined in the program's locale (category LC_NUMERIC). In the POSIX locale, or in a locale where the radix character is not defined, the radix character defaults to a period (.).

Each conversion specification is introduced by the % character or by the character sequence %n$, after which the following appear in sequence:

  • Flags: Zero or more (in any order), which modify the meaning of the conversion specification.
  • Field width: An optional minimum field width. If the converted value has fewer bytes than the field width, it will be padded with spaces by default on the left; it will be padded on the right if the left-adjustment flag (-) is given to the field width. The field width takes the form of an asterisk (*), or a decimal integer.
  • Precision: An optional precision that gives the minimum number of digits to appear for the d, i, o, u, x, and X conversions; the number of digits to appear after the radix character for the e, E, and f conversions; the maximum number of significant digits for the g and G conversions; or the maximum number of bytes to be printed from a string in s and S conversions. The precision takes the form of a period (.) followed either by an asterisk (*), or an optional decimal digit string, where a null digit string is treated as 0. If precision appears with any other conversion character, the behavior is undefined.
  • An optional h specifying that a following d, i, o, u, x, or X conversion character applies to a type short int or type unsigned short int (the argument will have been promoted according to the integral promotions, and its value will be converted to type or before printing); an optional l specifying that a following d, i, o, u, x, or X conversion character applies to a type long int or type unsigned long int; an optional L specifying that a following e, E, f, g, or G conversion character applies to a type long double argument; an optional q specifying that a following d, i, o, u, x, or X conversion character applies to a type quad_t or type u_quad_t argument; an optional Z specifying that a following s conversion character applies to a type char * argument.
Anteprima
Vedrai una selezione di 3 pagine su 6
Sistemi operativi - Syscall fprintf Pag. 1 Sistemi operativi - Syscall fprintf Pag. 2
Anteprima di 3 pagg. su 6.
Scarica il documento per vederlo tutto.
Sistemi operativi - Syscall fprintf Pag. 6
1 su 6
D/illustrazione/soddisfatti o rimborsati
Acquista con carta o PayPal
Scarica i documenti tutte le volte che vuoi
Dettagli
SSD
Scienze matematiche e informatiche INF/01 Informatica

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher N. A. di informazioni apprese con la frequenza delle lezioni di Sistemi operativi e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Università degli studi di Napoli Federico II o del prof Cotroneo Domenico.
Appunti correlati Invia appunti e guadagna

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community