Skip to content

Commit 6fe3169

Browse files
authored
Merge pull request MicrosoftDocs#3273 from MicrosoftDocs/FromPublicMasterBranch
Resolve syncing conflicts from FromPublicMasterBranch to master
2 parents 3681ff0 + 44be0d2 commit 6fe3169

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

docs/c-language/parsing-c-command-line-arguments.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
title: "Parsing C Command-Line Arguments"
3-
ms.date: "11/04/2016"
4-
helpviewer_keywords: ["quotation marks, command-line arguments", "double quotation marks", "command line, parsing", "parsing, command-line arguments", "startup code, parsing command-line arguments"]
3+
description: "Learn how the Microsoft C runtime startup code interprets command-line arguments to create the argv and argc parameters."
4+
ms.date: 11/09/2020
5+
helpviewer_keywords: ["quotation marks, command-line arguments", "double quotation marks", "double quote marks", "command line, parsing", "parsing, command-line arguments", "startup code, parsing command-line arguments"]
56
ms.assetid: ffce8037-2811-45c4-8db4-1ed787859c80
67
---
78
# Parsing C Command-Line Arguments
@@ -12,15 +13,17 @@ Microsoft C startup code uses the following rules when interpreting arguments gi
1213

1314
- Arguments are delimited by white space, which is either a space or a tab.
1415

15-
- A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. Note that the caret (**^**) is not recognized as an escape character or delimiter.
16+
- The first argument (`argv[0]`) is treated specially. It represents the program name. Because it must be a valid pathname, parts surrounded by double quote marks (**`"`**) are allowed. The double quote marks aren't included in the `argv[0]` output. The parts surrounded by double quote marks prevent interpretation of a space or tab character as the end of the argument. The later rules in this list don't apply.
1617

17-
- A double quotation mark preceded by a backslash, **\\"**, is interpreted as a literal double quotation mark (**"**).
18+
- A string surrounded by double quote marks is interpreted as a single argument, whether or not it contains white space. A quoted string can be embedded in an argument. The caret (**`^`**) isn't recognized as an escape character or delimiter. Within a quoted string, a pair of double quote marks is interpreted as a single escaped double quote mark. If the command line ends before a closing double quote mark is found, then all the characters read so far are output as the last argument.
1819

19-
- Backslashes are interpreted literally, unless they immediately precede a double quotation mark.
20+
- A double quote mark preceded by a backslash (**`\"`**) is interpreted as a literal double quote mark (**`"`**).
2021

21-
- If an even number of backslashes is followed by a double quotation mark, then one backslash (**\\**) is placed in the `argv` array for every pair of backslashes (**\\\\**), and the double quotation mark (**"**) is interpreted as a string delimiter.
22+
- Backslashes are interpreted literally, unless they immediately precede a double quote mark.
2223

23-
- If an odd number of backslashes is followed by a double quotation mark, then one backslash (**\\**) is placed in the `argv` array for every pair of backslashes (**\\\\**) and the double quotation mark is interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (**"**) to be placed in `argv`.
24+
- If an even number of backslashes is followed by a double quote mark, then one backslash (**`\`**) is placed in the `argv` array for every pair of backslashes (**`\\`**), and the double quote mark (**`"`**) is interpreted as a string delimiter.
25+
26+
- If an odd number of backslashes is followed by a double quote mark, then one backslash (**`\`**) is placed in the `argv` array for every pair of backslashes (**`\\`**). The double quote mark is interpreted as an escape sequence by the remaining backslash, causing a literal double quote mark (**`"`**) to be placed in `argv`.
2427

2528
This list illustrates the rules above by showing the interpreted result passed to `argv` for several examples of command-line arguments. The output listed in the second, third, and fourth columns is from the ARGS.C program that follows the list.
2629

@@ -31,13 +34,13 @@ This list illustrates the rules above by showing the interpreted result passed t
3134
|`a\\\b d"e f"g h`|`a\\\b`|`de fg`|`h`|
3235
|`a\\\"b c d`|`a\"b`|`c`|`d`|
3336
|`a\\\\"b c" d e`|`a\\b c`|`d`|`e`|
37+
|`a"b"" c d`|`ab" c d`|||
3438

3539
## Example
3640

3741
### Code
3842

3943
```c
40-
// Parsing_C_Commandline_args.c
4144
// ARGS.C illustrates the following variables used for accessing
4245
// command-line arguments and environment variables:
4346
// argc argv envp

docs/standard-library/ios-typedefs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main( )
6161
ofstream x( "iostream.txt" );
6262
x << "testing";
6363
streampos y = x.tellp( );
64-
cout << streamoff(y) << '\n';
64+
cout << streamoff( y ) << '\n';
6565
}
6666
```
6767
@@ -143,7 +143,7 @@ int main( )
143143
wofstream xw( "wiostream.txt" );
144144
xw << L"testing";
145145
wstreampos y = xw.tellp( );
146-
cout << y << endl;
146+
cout << streamoff( y ) << '\n';
147147
}
148148
```
149149

0 commit comments

Comments
 (0)