<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: arguments code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 06:00:47 GMT</pubDate>
    <description>DZone Snippets: arguments code</description>
    <item>
      <title>Simple way to check command line arguments in a C program</title>
      <link>http://snippets.dzone.com/posts/show/5175</link>
      <description>A simple way to check command line arguments.&lt;br /&gt;&lt;br /&gt;Author: &lt;a href="http://www.inf.ufrgs.br/~jmftrindade"&gt;Joana Matos Fonseca da Trindade&lt;/a&gt;&lt;br /&gt;Date: 2008.02.25&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;&lt;br /&gt;/* minimum required number of parameters */&lt;br /&gt;#define MIN_REQUIRED 2&lt;br /&gt;&lt;br /&gt;/* display usage */&lt;br /&gt;int help() {&lt;br /&gt;   printf("Usage: myprogram [-s &lt;arg0&gt;] [-n &lt;arg1&gt;] [-true]\n");&lt;br /&gt;   printf("\t-s: a string a\n");&lt;br /&gt;   printf("\t-n: a number\n");&lt;br /&gt;   printf("\t-true: a single parameter\n");&lt;br /&gt;&lt;br /&gt;   return 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* main */&lt;br /&gt;int main(int argc, char *argv[]) {&lt;br /&gt;   if (argc &lt; MIN_REQUIRED) {&lt;br /&gt;      return help();&lt;br /&gt;   }&lt;br /&gt;   int i;&lt;br /&gt;&lt;br /&gt;   /* iterate over all arguments */&lt;br /&gt;   for (i = 1; i &lt; (argc - 1); i++) {&lt;br /&gt;       if (strcmp("-s", argv[i]) == 0) {&lt;br /&gt;          /* do something with it */ &lt;br /&gt;          printf("string = %s\n", argv[++i]);&lt;br /&gt;          continue;&lt;br /&gt;       }&lt;br /&gt;       if (strcmp("-n", argv[i]) == 0) {&lt;br /&gt;          /* do something with it. for example, convert it to an integer */&lt;br /&gt;          printf("number = %i\n", atoi(argv[++i]));&lt;br /&gt;          continue;&lt;br /&gt;       }&lt;br /&gt;       if (strcmp("-true", argv[i]) == 0) {&lt;br /&gt;          printf("true activated\n");&lt;br /&gt;          continue;&lt;br /&gt;       }&lt;br /&gt;       return help();&lt;br /&gt;   }&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 25 Feb 2008 22:49:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5175</guid>
      <author>jmftrindade (Joana M. F. da Trindade)</author>
    </item>
    <item>
      <title>basic batch conditional evaluation</title>
      <link>http://snippets.dzone.com/posts/show/4138</link>
      <description>// check if argument has been passed to batch file&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if not [%1]==[] echo %1&lt;br /&gt;if not [%1]'==' echo %1&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 13 Jun 2007 15:42:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4138</guid>
      <author>thefamousnomo (Robin)</author>
    </item>
    <item>
      <title>Python keyword arguments</title>
      <link>http://snippets.dzone.com/posts/show/2502</link>
      <description>This is something I always forget how to do, and it's kind of hard to Google or search the Python docs because you can't search for **.&lt;br /&gt;&lt;br /&gt;The point is, when using **kwargs, you have to use the ** prefix not only in the function definition, but also in the call, prefixed to the variable you want to use as a keyword dictionary. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; d = dict(zip(list('123'),list('abc')))&lt;br /&gt;&gt;&gt;&gt; d&lt;br /&gt;{'1': 'a', '3': 'c', '2': 'b'}&lt;br /&gt;&gt;&gt;&gt; def printkwargs(**kwargs):&lt;br /&gt;...  for k,v in kwargs.items(): print k,v&lt;br /&gt;...&lt;br /&gt;&gt;&gt;&gt; printkwargs(**d)&lt;br /&gt;1 a&lt;br /&gt;3 c&lt;br /&gt;2 b&lt;br /&gt;&gt;&gt;&gt; printkwargs(d)&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;  File "&lt;stdin&gt;", line 1, in ?&lt;br /&gt;TypeError: printkwargs() takes exactly 0 arguments (1 given)&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; # you have to tell python that you want the argument to be treated as a keyword dictionary by prefixing it with **&lt;br /&gt;&gt;&gt;&gt; # more info at http://mail.python.org/pipermail/python-list/2006-March/332182.html&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Aug 2006 00:21:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2502</guid>
      <author>snifty (Pat Hall)</author>
    </item>
  </channel>
</rss>
