<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Passing an integer argument to a C program on command line in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191357#M51097</link>
    <description>Hello folks;&lt;BR /&gt;&lt;BR /&gt;A bit off-topic but I *am* using GCC on a Linux box.  :-)&lt;BR /&gt;&lt;BR /&gt;I have written a program, that at startup, I would like to enter an integer on the command line and pass it to the program. &lt;BR /&gt;&lt;BR /&gt;All I can find is the ARGV and that only appears to pass an array of pointers.&lt;BR /&gt;&lt;BR /&gt;    int main(int argc, char *argc[])&lt;BR /&gt;&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;(Oh - I came up with a work-around which is taking the pointer and doing a STRCMP with a known value and if there is a match setting the variable to the integer I would have put on the command line. I just can't believe that with all the flexibility of C that there isn't a better way. I *DID* look thru a lot of my C programming books but could not any reference).&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;tonyp (aka hunybuny)&lt;BR /&gt;</description>
    <pubDate>Wed, 05 Aug 2009 01:39:04 GMT</pubDate>
    <dc:creator>tony j. podrasky</dc:creator>
    <dc:date>2009-08-05T01:39:04Z</dc:date>
    <item>
      <title>Passing an integer argument to a C program on command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191357#M51097</link>
      <description>Hello folks;&lt;BR /&gt;&lt;BR /&gt;A bit off-topic but I *am* using GCC on a Linux box.  :-)&lt;BR /&gt;&lt;BR /&gt;I have written a program, that at startup, I would like to enter an integer on the command line and pass it to the program. &lt;BR /&gt;&lt;BR /&gt;All I can find is the ARGV and that only appears to pass an array of pointers.&lt;BR /&gt;&lt;BR /&gt;    int main(int argc, char *argc[])&lt;BR /&gt;&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;(Oh - I came up with a work-around which is taking the pointer and doing a STRCMP with a known value and if there is a match setting the variable to the integer I would have put on the command line. I just can't believe that with all the flexibility of C that there isn't a better way. I *DID* look thru a lot of my C programming books but could not any reference).&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;tonyp (aka hunybuny)&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Aug 2009 01:39:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191357#M51097</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2009-08-05T01:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an integer argument to a C program on command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191358#M51098</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [..] I *am* using GCC on a Linux box. [...]&lt;BR /&gt;&lt;BR /&gt;I'm not, but:&lt;BR /&gt;&lt;BR /&gt;alp $ type nil.c&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;&lt;BR /&gt;main( int argc, char **argv)&lt;BR /&gt;{&lt;BR /&gt;    long val;&lt;BR /&gt;&lt;BR /&gt;    if (argc &amp;gt; 1)&lt;BR /&gt;    {&lt;BR /&gt;        val = strtol( argv[ 1], NULL, 10);&lt;BR /&gt;        printf( " val = %ld.\n", val);&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;alp $ cc nil&lt;BR /&gt;alp $ link nil&lt;BR /&gt;&lt;BR /&gt;alp $ exec nil&lt;BR /&gt;&lt;BR /&gt;alp $ exec nil 29 30 31&lt;BR /&gt; val = 29.&lt;BR /&gt;&lt;BR /&gt;alp $ cc /version&lt;BR /&gt;HP C V7.3-009 on OpenVMS Alpha V7.3-2&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Seems to work with a GCC somewhere, too:&lt;BR /&gt;&lt;BR /&gt;sol# gcc -o nil nil.c&lt;BR /&gt;sol# ./nil&lt;BR /&gt;sol# ./nil 19 20 21&lt;BR /&gt; val = 19.&lt;BR /&gt;&lt;BR /&gt;sol# uname -a&lt;BR /&gt;SunOS sol 5.10 Generic_137137-09 sun4u sparc sun4u&lt;BR /&gt;sol# gcc --version&lt;BR /&gt;gcc (GCC) 3.4.6&lt;BR /&gt;[...]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The program gets a string, but, given a&lt;BR /&gt;string, many things are possible.&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 05 Aug 2009 02:05:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191358#M51098</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-08-05T02:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an integer argument to a C program on command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191359#M51099</link>
      <description>There are many ways to convert a string to an integer. Steven already mentioned strtol(), but there is also atoi(). If your command line argument may contain "an integer and something else" (e.g. something like "10k"), you can use sscanf().&lt;BR /&gt;&lt;BR /&gt;See also getopt(): it is a bit complicated but makes it easy to parse a large number of options in any order.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Wed, 05 Aug 2009 05:59:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191359#M51099</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2009-08-05T05:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an integer argument to a C program on command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191360#M51100</link>
      <description>Dear Steven and Matti;&lt;BR /&gt;&lt;BR /&gt;Thank you for the help.&lt;BR /&gt;&lt;BR /&gt;The suggestion works perfectly!&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;tonyp (aka hunybuny)&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Aug 2009 15:40:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191360#M51100</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2009-08-05T15:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an integer argument to a C program on command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191361#M51101</link>
      <description>Members provided the solution.&lt;BR /&gt;&lt;BR /&gt;Problem Resolved.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;tonyp (aka hunybuny)&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Aug 2009 17:30:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/passing-an-integer-argument-to-a-c-program-on-command-line/m-p/5191361#M51101</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2009-08-10T17:30:00Z</dc:date>
    </item>
  </channel>
</rss>

