Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C syntax
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Command-line arguments=== The [[parameter]]s given on a [[command line]] are passed to a C program with two predefined variables - the count of the command-line arguments in {{code|argc}} and the individual [[Parameter|arguments]] as [[character string]]s in the pointer array {{code|argv}}. So the command: myFilt p1 p2 p3 results in something like: {|class="wikitable" style="font-family: monospace,monospace;" |- |m||y||F||i||l||t||style="background:#CCC;"|\0||p||1||style="background:#CCC;"|\0||p||2||style="background:#CCC;"|\0||p||3||style="background:#CCC;"|\0 |- |colspan="7" align="center"|argv[0]||colspan="3" align="center"|argv[1]||colspan="3" align="center"|argv[2]||colspan="3" align="center"|argv[3] |} While individual strings are arrays of contiguous characters, there is no guarantee that the strings are stored as a contiguous group. The name of the program, {{code|argv[0]}}, may be useful when printing diagnostic messages or for making one binary serve multiple purposes. The individual values of the parameters may be accessed with {{code|argv[1]}}, {{code|argv[2]}}, and {{code|argv[3]}}, as shown in the following program: <syntaxhighlight lang=C> #include <stdio.h> int main(int argc, char *argv[]) { printf("argc\t= %d\n", argc); for (int i = 0; i < argc; i++) printf("argv[%i]\t= %s\n", i, argv[i]); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)