Skip to content

Commit 660abf4

Browse files
author
Matthew Sebolt
authored
* batch * revisions * revisions * Update chrono.md
1 parent 06def7a commit 660abf4

10 files changed

+201
-201
lines changed

docs/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.date: "10/26/2020"
55
helpviewer_keywords: ["format specification fields for printf function", "printf function format specification fields", "flag directives, printf function", "type fields, printf function", "width fields, printf function", "precision fields, printf function"]
66
ms.assetid: 664b1717-2760-4c61-bd9c-22eee618d825
77
---
8-
# Format specification syntax: printf and wprintf functions
8+
# Format specification syntax: `printf` and `wprintf` functions
99

1010
The various `printf` and `wprintf` functions take a format string and optional arguments and produce a formatted sequence of characters for output. The format string contains zero or more *directives*, which are either literal characters for output or encoded *conversion specifications* that describe how to format an argument in the output. This article describes the syntax used to encode conversion specifications in the format string. For a listing of these functions, see [Stream I/O](../c-runtime-library/stream-i-o.md).
1111

@@ -122,31 +122,31 @@ The first optional field in a conversion specification contains *flag directives
122122

123123
## Width specification
124124

125-
In a conversion specification, the optional width specification field appears after any *flags* characters. The *width* argument is a non-negative decimal integer that controls the minimum number of characters that are output. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values—depending on whether the left-alignment flag (**`-`**) is specified—until the minimum width is reached. If *width* is prefixed by 0, leading zeros are added to integer or floating-point conversions until the minimum width is reached, except when conversion is to an infinity or NaN.
125+
In a conversion specification, the optional width specification field appears after any *flags* characters. The *`width`* argument is a non-negative decimal integer that controls the minimum number of characters that are output. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values—depending on whether the left-alignment flag (**`-`**) is specified—until the minimum width is reached. If *`width`* is prefixed by 0, leading zeros are added to integer or floating-point conversions until the minimum width is reached, except when conversion is to an infinity or `NaN`.
126126

127-
The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if *width* isn't provided, all characters of the value are output, subject to the *precision* specification.
127+
The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if *`width`* isn't provided, all characters of the value are output, subject to the precision specification.
128128

129-
If the width specification is an asterisk (`*`), an `int` argument from the argument list supplies the value. The *width* argument must precede the value that's being formatted in the argument list, as shown in this example:
129+
If the width specification is an asterisk (`*`), an `int` argument from the argument list supplies the value. The *`width`* argument must precede the value that's being formatted in the argument list, as shown in this example:
130130

131131
`printf("%0*d", 5, 3); /* 00003 is output */`
132132

133-
A missing or small *width* value in a conversion specification doesn't cause the truncation of an output value. If the result of a conversion is wider than the *width* value, the field expands to contain the conversion result.
133+
A missing or small *`width`* value in a conversion specification doesn't cause the truncation of an output value. If the result of a conversion is wider than the *`width`* value, the field expands to contain the conversion result.
134134

135135
<a name="precision"></a>
136136

137137
## Precision specification
138138

139139
In a conversion specification, the third optional field is the precision specification. It consists of a period (`.`) followed by a non-negative decimal integer that, depending on the conversion type, specifies the number of string characters, the number of decimal places, or the number of significant digits to be output.
140140

141-
Unlike the width specification, the precision specification can cause either truncation of the output value or rounding of a floating-point value. If *precision* is specified as 0, and the value to be converted is 0, the result is no characters output, as shown in this example:
141+
Unlike the width specification, the precision specification can cause either truncation of the output value or rounding of a floating-point value. If *`precision`* is specified as 0, and the value to be converted is 0, the result is no characters output, as shown in this example:
142142

143143
`printf( "%.0d", 0 ); /* No characters output */`
144144

145-
If the precision specification is an asterisk (`*`), an `int` argument from the argument list supplies the value. In the argument list, the *precision* argument must precede the value that's being formatted, as shown in this example:
145+
If the precision specification is an asterisk (`*`), an `int` argument from the argument list supplies the value. In the argument list, the *`precision`* argument must precede the value that's being formatted, as shown in this example:
146146

147147
`printf( "%.*f", 3, 3.14159265 ); /* 3.142 output */`
148148

149-
The *type* character determines either the interpretation of *precision* or the default precision when *precision* is omitted, as shown in the following table.
149+
The *`type`* character determines either the interpretation of *`precision`* or the default precision when *`precision`* is omitted, as shown in the following table.
150150

151151
### How Precision Values Affect Type
152152

@@ -199,6 +199,6 @@ An **`hc`** or **`hC`** type specifier is synonymous with **`c`** in `printf` fu
199199
200200
## See also
201201

202-
[`printf, _printf_l, wprintf, _wprintf_l`](../c-runtime-library/reference/printf-printf-l-wprintf-wprintf-l.md)\
203-
[`printf_s, _printf_s_l, wprintf_s, _wprintf_s_l`](../c-runtime-library/reference/printf-s-printf-s-l-wprintf-s-wprintf-s-l.md)\
202+
[`printf`, `_printf_l`, `wprintf`, `_wprintf_l`](../c-runtime-library/reference/printf-printf-l-wprintf-wprintf-l.md)\
203+
[`printf_s`, `_printf_s_l`, `wprintf_s`, `_wprintf_s_l`](../c-runtime-library/reference/printf-s-printf-s-l-wprintf-s-wprintf-s-l.md)\
204204
[`printf_p` Positional Parameters](../c-runtime-library/printf-p-positional-parameters.md)

docs/c-runtime-library/reference/fopen-s-wfopen-s.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ helpviewer_keywords: ["_wfopen_s function", "opening files, for file I/O", "_tfo
1111
---
1212
# `fopen_s`, `_wfopen_s`
1313

14-
Opens a file. These versions of [`fopen, _wfopen`](fopen-wfopen.md) have security enhancements, as described in [Security Features in the CRT](../../c-runtime-library/security-features-in-the-crt.md).
14+
Opens a file. These versions of [`fopen`, `_wfopen`](fopen-wfopen.md) have security enhancements, as described in [Security Features in the CRT](../../c-runtime-library/security-features-in-the-crt.md).
1515

1616
## Syntax
1717

@@ -41,7 +41,7 @@ Type of access permitted.
4141

4242
## Return Value
4343

44-
Zero if successful; an error code on failure. For more information about these error codes, see [`errno, _doserrno, _sys_errlist, and _sys_nerr`](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
44+
Zero if successful; an error code on failure. For more information about these error codes, see [`errno`, `_doserrno`, `_sys_errlist`, and `_sys_nerr`](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
4545

4646
### Error Conditions
4747

@@ -53,15 +53,15 @@ Zero if successful; an error code on failure. For more information about these e
5353

5454
## Remarks
5555

56-
Files that are opened by **`fopen_s`** and **`_wfopen_s`** aren't sharable. If you require that a file be sharable, use [`_fsopen, _wfsopen`](fsopen-wfsopen.md) with the appropriate sharing mode constant—for example, **`_SH_DENYNO`** for read/write sharing.
56+
Files that are opened by **`fopen_s`** and **`_wfopen_s`** aren't sharable. If you require that a file be sharable, use [`_fsopen`, `_wfsopen`](fsopen-wfsopen.md) with the appropriate sharing mode constant—for example, **`_SH_DENYNO`** for read/write sharing.
5757

5858
The **`fopen_s`** function opens the file that's specified by *filename*. **`_wfopen_s`** is a wide-character version of **`fopen_s`**; the arguments to **`_wfopen_s`** are wide-character strings. **`_wfopen_s`** and **`fopen_s`** behave identically otherwise.
5959

6060
**`fopen_s`** accepts paths that are valid on the file system at the point of execution; UNC paths and paths that involve mapped network drives are accepted by **`fopen_s`** as long as the system that's executing the code has access to the share or mapped network drive at the time of execution. When you construct paths for **`fopen_s`**, don't make assumptions about the availability of drives, paths, or network shares in the execution environment. You can use either forward slashes (/) or backslashes (\\) as the directory separators in a path.
6161

6262
These functions validate their parameters. If *`pFile`*, *`filename`*, or *`mode`* is a null pointer, these functions generate an invalid parameter exception, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md).
6363

64-
Always check the return value to see if the function succeeded before you do any further operations on the file. If an error occurs, the error code is returned and the global variable **`errno`** is set. For more information, see [`errno, _doserrno, _sys_errlist, and _sys_nerr`](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
64+
Always check the return value to see if the function succeeded before you do any further operations on the file. If an error occurs, the error code is returned and the global variable **`errno`** is set. For more information, see [`errno`, `_doserrno`, `_sys_errlist`, and `_sys_nerr`](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
6565

6666
By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).
6767

@@ -111,7 +111,7 @@ The character string *`mode`* specifies the kind of access that's requested for
111111

112112
When a file is opened by using the **`"a"`** or **`"a+"`** access type, all write operations occur at the end of the file. The file pointer can be repositioned by using [`fseek`](fseek-fseeki64.md) or [`rewind`](rewind.md), but it's always moved back to the end of the file before any write operation is carried out so that existing data cannot be overwritten.
113113

114-
The **`"a"`** mode doesn't remove the EOF marker before appending to the file. After appending has occurred, the MS-DOS `TYPE` command only shows data up to the original EOF marker and not any data that's appended to the file. The **`"a+"`** mode does remove the EOF marker before appending to the file. After appending, the MS-DOS `TYPE` command shows all data in the file. The **`"a+"`** mode is required for appending to a stream file that is terminated with the `CTRL+Z` EOF marker.
114+
The **`"a"`** mode doesn't remove the EOF marker before appending to the file. After appending has occurred, the MS-DOS `TYPE` command only shows data up to the original EOF marker and not any data that's appended to the file. The **`"a+"`** mode does remove the EOF marker before appending to the file. After appending, the MS-DOS `TYPE` command shows all data in the file. The **`"a+"`** mode is required for appending to a stream file that is terminated with the **CTRL**+**Z** EOF marker.
115115

116116
When the **`"r+"`**, **`"w+"`**, or **`"a+"`** access type is specified, both reading and writing are allowed. (The file is said to be open for "update".) However, when you switch from reading to writing, the input operation must come across an EOF marker. If there's no EOF marker, you must use an intervening call to a file-positioning function. The file-positioning functions are **`fsetpos`**, [`fseek`](fseek-fseeki64.md), and [`rewind`](rewind.md). When you switch from writing to reading, you must use an intervening call to either **`fflush`** or to a file-positioning function.
117117

@@ -124,7 +124,7 @@ In addition to the values above, the following characters can be included in *`m
124124
| **`t`** | Open in text (translated) mode. |
125125
| **`b`** | Open in binary (untranslated) mode; translations involving carriage-return and line feed characters are suppressed. |
126126

127-
In text (translated) mode, `CTRL+Z` is interpreted as an end-of-file character on input. In files opened for reading/writing with **`"a+"`**, **`fopen_s`** checks for a `CTRL+Z` at the end of the file and removes it, if possible. This is done because using [`fseek`](fseek-fseeki64.md) and **`ftell`** to move within a file that ends with a `CTRL+Z`, may cause [`fseek`](fseek-fseeki64.md) to behave improperly near the end of the file.
127+
In text (translated) mode, **CTRL**+**Z** is interpreted as an end-of-file character on input. In files opened for reading/writing with **`"a+"`**, **`fopen_s`** checks for a **CTRL**+**Z** at the end of the file and removes it, if possible. This is done because using [`fseek`](fseek-fseeki64.md) and **`ftell`** to move within a file that ends with a **CTRL**+**Z**, may cause [`fseek`](fseek-fseeki64.md) to behave improperly near the end of the file.
128128

129129
Also, in text mode, carriage return/line feed combinations are translated into single line feeds on input, and line feed characters are translated to carriage return-line feed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. The Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the **`mbtowc`** function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the **`wctomb`** function).
130130

@@ -249,10 +249,10 @@ Number of files closed by _fcloseall: 1
249249
## See also
250250

251251
[Stream I/O](../../c-runtime-library/stream-i-o.md)\
252-
[`fclose, _fcloseall`](fclose-fcloseall.md)\
253-
[`_fdopen, _wfdopen`](fdopen-wfdopen.md)\
252+
[`fclose`, `_fcloseall`](fclose-fcloseall.md)\
253+
[`_fdopen`, `_wfdopen`](fdopen-wfdopen.md)\
254254
[`ferror`](ferror.md)\
255255
[`_fileno`](fileno.md)\
256-
[`freopen, _wfreopen`](freopen-wfreopen.md)\
257-
[`_open, _wopen`](open-wopen.md)\
256+
[`freopen`, `_wfreopen`](freopen-wfreopen.md)\
257+
[`_open`, `_wopen`](open-wopen.md)\
258258
[`_setmode`](setmode.md)

0 commit comments

Comments
 (0)