Skip to content

Fix error in example and update _vcprintf_p reference #5638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Each of these functions takes a pointer to an argument list, and then uses the `

The versions of these functions that have the `_l` suffix are identical except that they use the locale parameter that's passed in instead of the current locale.

Each *`argument`* (if any) is converted and is output according to the corresponding format specification in *`format`*. The format specification supports positional parameters so that you can specify the order in which the arguments are used in the format string. For more information, see [printf_p Positional Parameters](../printf-p-positional-parameters.md).
Each *`argument`* (if any) is converted and is output according to the corresponding format specification in *`format`*. The format specification supports positional parameters so that you can specify the order in which the arguments are used in the format string. For more information, see [`printf_p` positional parameters](../printf-p-positional-parameters.md).

These functions don't translate line-feed characters on output into carriage return-line feed (CR-LF) combinations.

Expand All @@ -73,7 +73,7 @@ These functions validate the input pointer and the format string. If *`format`*

### Generic-text routine mappings

| Tchar.h routine | `_UNICODE` and `_MBCS` not defined | `_MBCS` defined | `_UNICODE` defined |
| `Tchar.h` routine | `_UNICODE` and `_MBCS` not defined | `_MBCS` defined | `_UNICODE` defined |
|---|---|---|---|
| `_vtcprintf_p` | **`_vcprintf_p`** | **`_vcprintf_p`** | **`_vcwprintf_p`** |
| `_vtcprintf_p_l` | **`_vcprintf_p_l`** | **`_vcprintf_p_l`** | **`_vcwprintf_p_l`** |
Expand All @@ -82,8 +82,8 @@ These functions validate the input pointer and the format string. If *`format`*

| Routine | Required header |
|---|---|
| **`_vcprintf_p`**, **`_vcprintf_p_l`** | \<conio.h> and \<stdarg.h> |
| **`_vcwprintf_p`**, **`_vcwprintf_p_l`** | \<conio.h> and \<stdarg.h> |
| **`_vcprintf_p`**, **`_vcprintf_p_l`** | `<conio.h>` and `<stdarg.h>` |
| **`_vcwprintf_p`**, **`_vcwprintf_p_l`** | `<conio.h>` and `<stdarg.h>` |

For more compatibility information, see [Compatibility](../compatibility.md).

Expand All @@ -101,18 +101,18 @@ For more compatibility information, see [Compatibility](../compatibility.md).
// An error formatting function that's used to print to the console.
int eprintf(const char* format, ...)
{
va_list args;
va_start(args, format);
int result = _vcprintf_p(format, args);
va_end(args);
return result;
va_list args;
va_start(args, format);
int result = _vcprintf_p(format, args);
va_end(args);
return result;
}

int main()
{
int n = eprintf("parameter 2 = %2$d; parameter 1 = %1$s\r\n",
"one", 222);
_cprintf_s("%d characters printed\r\n");
int n = eprintf("parameter 2 = %2$d; parameter 1 = %1$s\r\n",
"one", 222);
_cprintf_s("%d characters printed\r\n", n);
}
```

Expand All @@ -126,4 +126,4 @@ parameter 2 = 222; parameter 1 = one
[Console and port I/O](../console-and-port-i-o.md)\
[`_cprintf`, `_cprintf_l`, `_cwprintf`, `_cwprintf_l`](cprintf-cprintf-l-cwprintf-cwprintf-l.md)\
[`va_arg`, `va_copy`, `va_end`, `va_start`](va-arg-va-copy-va-end-va-start.md)\
[printf_p Positional Parameters](../printf-p-positional-parameters.md)
[`printf_p` positional parameters](../printf-p-positional-parameters.md)