<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: program code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 09:09:36 GMT</pubDate>
    <description>DZone Snippets: program 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>Making SQLITE/SQLITE3 executable scripts.</title>
      <link>http://snippets.dzone.com/posts/show/3080</link>
      <description>Use "here document" statements to build complex script files with embedded SQL statements via the sqlite/sqlite3 utility.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /usr/bin/env bash&lt;br /&gt;&lt;br /&gt;# execute some bash scripting commands here&lt;br /&gt;&lt;br /&gt;sqlite3 mydatabase &lt;&lt;SQL_ENTRY_TAG_1&lt;br /&gt;SELECT * &lt;br /&gt;  FROM mytable &lt;br /&gt;  WHERE somecondition='somevalue';&lt;br /&gt;SQL_ENTRY_TAG_1&lt;br /&gt;&lt;br /&gt;# execute other bash scripting commands here&lt;br /&gt;&lt;br /&gt;sqlite3 mydatabase &lt;&lt;SQL_ENTRY_TAG_2&lt;br /&gt;SELECT *&lt;br /&gt;  FROM myothertable&lt;br /&gt;  WHERE someothercondition='someothervalue';&lt;br /&gt;SQL_ENTRY_TAG_2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note that being in a bash script means that you can expand $-variables inside the SQL code directly.  This is, however, not advised unless you can be sure that only trusted, competent people will run your code.  Otherwise you'll be facing SQL injection attacks.</description>
      <pubDate>Mon, 04 Dec 2006 18:54:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3080</guid>
      <author>ttmrichter (Michael T. Richter)</author>
    </item>
    <item>
      <title>Making MySQL executable scripts.</title>
      <link>http://snippets.dzone.com/posts/show/3078</link>
      <description>Use "here document" statements to build complex script files with embedded SQL statements via the mysql utility.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /usr/bin/env bash&lt;br /&gt;&lt;br /&gt;# execute some bash scripting commands here&lt;br /&gt;&lt;br /&gt;mysql mydatabase &lt;&lt;SQL_ENTRY_TAG_1&lt;br /&gt;SELECT * &lt;br /&gt;  FROM mytable &lt;br /&gt;  WHERE somecondition='somevalue';&lt;br /&gt;SQL_ENTRY_TAG_1&lt;br /&gt;&lt;br /&gt;# execute other bash scripting commands here&lt;br /&gt;&lt;br /&gt;mysql mydatabase &lt;&lt;SQL_ENTRY_TAG_2&lt;br /&gt;SELECT *&lt;br /&gt;  FROM myothertable&lt;br /&gt;  WHERE someothercondition='someothervalue';&lt;br /&gt;SQL_ENTRY_TAG_2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note that being in a bash script means that you can expand $-variables inside the SQL code directly.  This is, however, not advised unless you can be sure that only trusted, competent people will run your code.  Otherwise you'll be facing SQL injection attacks.</description>
      <pubDate>Mon, 04 Dec 2006 18:34:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3078</guid>
      <author>ttmrichter (Michael T. Richter)</author>
    </item>
  </channel>
</rss>
