{"id":401,"date":"2020-06-09T11:49:00","date_gmt":"2020-06-09T15:49:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=401"},"modified":"2024-02-08T08:19:06","modified_gmt":"2024-02-08T13:19:06","slug":"reading-command-line-input-in-c","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/reading-command-line-input-in-c\/","title":{"rendered":"Reading command-line input in C"},"content":{"rendered":"\n<p>Following a program which echos whatever you type in the command line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n\nmain(int argc, char *argv&#91;]) {\n     int i;\n     for(i = 0; i &lt; argc; i++)  { \n         printf(\"arg %d: %s\\n\", i, argv&#91;i]); \n     }\n     return 0;\n}<\/code><\/pre>\n\n\n\n<p>argc is the count of the number of command-line arguments. argv is array of vectors. Each word is a string. So if you type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>myprogram.exe my input<\/code><\/pre>\n\n\n\n<p>the output should be<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>argv&#91;0] = myprogram.exe\nargv&#91;1] = my\nargv&#91;2] = input<\/code><\/pre>\n\n\n\n<p>The terms argc and argv are used by convention.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following a program which echos whatever you type in the command line. argc is the count of the number of command-line arguments. argv is array of vectors. Each word is a string. So if you type: the output should be The terms argc and argv are used by convention.<\/p>\n","protected":false},"author":1,"featured_media":407,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[512],"tags":[],"class_list":["post-401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-misc"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":2,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"predecessor-version":[{"id":403,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/401\/revisions\/403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/407"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}