summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2015-10-12 22:58:48 -0500
committerLevi Bostian <levi.bostian@gmail.com>2015-10-12 22:58:48 -0500
commit1dc869a2f3cc43ce95caaf324c55687071295997 (patch)
tree837a1478da0abad7eaae8aab066409a059f4cb59
parent6849c34771f2810925a6b5c452198cddb8d84413 (diff)
parente8e8b9c76fb578d3f8e90b90b3c8a1c59cf0e901 (diff)
Merge pull request #1425 from AndyBrown91/C
[C/en] Accessing command line arguments in main
-rw-r--r--c.html.markdown10
1 files changed, 10 insertions, 0 deletions
diff --git a/c.html.markdown b/c.html.markdown
index db2ac930..345dca7f 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -27,6 +27,7 @@ Multi-line comments don't nest /* Be careful */ // comment ends on this line...
*/ // ...not this one!
// Constants: #define <keyword>
+// Constants are written in all-caps out of convention, not requirement
#define DAYS_IN_YEAR 365
// Enumeration constants are also ways to declare constants.
@@ -56,6 +57,15 @@ int add_two_ints(int x1, int x2); // function prototype
// Your program's entry point is a function called
// main with an integer return type.
int main(void) {
+ // your program
+}
+
+// The command line arguments used to run your program are also passed to main
+// argc being the number of arguments - your program's name counts as 1
+// argv is an array of character arrays - containing the arguments themselves
+// argv[0] = name of your program, argv[1] = first argument, etc.
+int main (int argc, char** argv)
+{
// print output using printf, for "print formatted"
// %d is an integer, \n is a newline
printf("%d\n", 0); // => Prints 0