<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eTechTips &#187; Programming</title>
	<atom:link href="http://www.etechtips.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.etechtips.com</link>
	<description>Your Technical resource</description>
	<lastBuildDate>Wed, 01 Feb 2012 21:38:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>C: Check if string is a number</title>
		<link>http://www.etechtips.com/2012/01/10/c-check-if-string-is-a-number/</link>
		<comments>http://www.etechtips.com/2012/01/10/c-check-if-string-is-a-number/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 16:04:44 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=595</guid>
		<description><![CDATA[I was recently testing some basic input and wrote this code to test if the input was a number or not. #include int main() { char name[10]; scanf("%s",&#038;name); if (checkifNumber(name)) { printf("Is a number\n"); } else { printf("Invalid number\n"); } } int checkifNumber(char *inp) { int i=0; int isanumber = 1; while(inp[i] != '\0' &#038;&#038; [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently testing some basic input and wrote this code to test if the input was a number or not.</p>
<pre>
#include <stdio.h>

int main()
{
  char name[10];

  scanf("%s",&#038;name);
  if (checkifNumber(name))
  {
     printf("Is a number\n");
  }
  else
  {
     printf("Invalid number\n");
  }
}

int checkifNumber(char *inp)
{
  int i=0;
  int isanumber = 1;

  while(inp[i] != '\0' &#038;&#038; i < 10)
  {
    if (inp[i] >= '0' &#038;&#038; inp[i] <= '9')
    {
    }
    else
    {
      isanumber =0;
    }
    i++;
  }
  return isanumber;
}
</pre>
<p>One thing that could be improved is to potentially use a global variable to define the length of the<br />
input string as it is used in two different places in the program and could potentially lead to an<br />
array overrun/underrun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/10/c-check-if-string-is-a-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA: XMLGregorianCalendar Dates</title>
		<link>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/</link>
		<comments>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 13:07:27 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=536</guid>
		<description><![CDATA[I was updating some plugins for a project and came to a query for an e-mail program I was writing, I had to send out recently introduced defects to their respective owners and insure that they would only get the defects from the a given offset. It turned out that my API had a XMLGregorianCalendar [...]]]></description>
			<content:encoded><![CDATA[<p>I was updating some plugins for a project and came to a query for an e-mail program I was writing,  I had to send out recently introduced defects to their respective owners and insure that they would only get the defects from the a given offset.  It turned out that my API had a XMLGregorianCalendar argument.  So I went out to look for a way to offset the date object so I could retrieve the correct information.  </p>
<p>I used the following to convert my date:</p>
<pre>
package com.etechtips;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class UpdateDate {

	public static void main(String[] args) {
		XMLGregorianCalendar xgcstart;
		GregorianCalendar gc;
		int daycount = 0;
		if (args.length != 1)
		{
			System.out.println("Need to specify offset");
			System.exit(1);
		}

		daycount = Integer.parseInt(args[0]);

		// This will get the current date based on System time of an object
		gc = new GregorianCalendar();
		System.out.println("CURRENT:" + gc.toString());

		// This will offset the date by daycount days
		gc.add(Calendar.DATE, daycount);
		System.out.println("OFFSET: "+ gc.toString());

		try
		{
			// Now the XMLGregorianCalendar object has an
                        instance that is based on the time set in the gc object
			xgcstart = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
		}
		catch(DatatypeConfigurationException dce)
		{
			dce.printStackTrace();
			System.exit(1);
		}

		// Code omitted
	}
}
</pre>
<p>Output:</p>
<pre>
CURRENT:java.util.GregorianCalendar[time=1321793315934,areFieldsSet=true,areAllFieldsSet=true,\
lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Chicago",offset=-21600000,\
dstSavings=3600000,useDaylight=true,transitions=235,\
lastRule=java.util.SimpleTimeZone[id=America/Chicago,offset=-21600000,dstSavings=3600000,\
useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,\
startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,\
endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=10,\
WEEK_OF_YEAR=48,WEEK_OF_MONTH=4,<strong>DAY_OF_MONTH=20</strong>,DAY_OF_YEAR=324,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=3,\
AM_PM=0,HOUR=6,HOUR_OF_DAY=6,MINUTE=48,SECOND=35,MILLISECOND=934,ZONE_OFFSET=-21600000,\
DST_OFFSET=0]
OFFSET: java.util.GregorianCalendar[time=1321706915934,areFieldsSet=true,areAllFieldsSet=true,\
lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Chicago",offset=-21600000,\
dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/Chicago,\
offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,\
startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,\
endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,\
YEAR=2011,MONTH=10,WEEK_OF_YEAR=47,WEEK_OF_MONTH=3,<strong>DAY_OF_MONTH=19</strong>,DAY_OF_YEAR=323,\
DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=6,HOUR_OF_DAY=6,MINUTE=48,SECOND=35,\
MILLISECOND=934,ZONE_OFFSET=-21600000,DST_OFFSET=0]
</pre>
<p>The printouts above show the current date and the new date based on the offset.  I made the day of the month bold in the printouts to show what the offset has updated the date.  You could put a much larger offset than 1 and Calendar object will take care of updating the day of week, week of year and more. You will not need to deal with checking for leap year or dealing with updating all the month and years, this is all taken care of for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl: CPAN installing modules</title>
		<link>http://www.etechtips.com/2011/08/05/perl-cpan-installing-modules/</link>
		<comments>http://www.etechtips.com/2011/08/05/perl-cpan-installing-modules/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 14:00:42 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=338</guid>
		<description><![CDATA[Sometimes it is necessary to install other modules into the Perl environment. Luckily there is a great repository of modules known as CPAN (The Comprehensive Perl Archive Network). This lets you install modules to help with encryption, XML,YAML, and many other things. There are a few ways to install a package and here are the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is necessary to install other modules into the Perl environment.  Luckily there is a great repository of modules known as CPAN (The Comprehensive Perl Archive Network). This lets you install modules to help with encryption, XML,YAML, and many other things.  There are a few ways to install a package and here are the ones that I use the most.</p>
<p>Using the CPAN shell:</p>
<pre>perl -MCPAN -e shell</pre>
<p>This will open a command prompt that will let you search for CPAN modules with:</p>
<pre>i /PACKAGENAME/</pre>
<p>or install a new module:</p>
<pre>install /DateTime/</pre>
<p>The nice thing about installing with CPAN is that it will look for the dependencies and suggest installing them before the module you requested.</p>
<p><em>NOTE:</em>This can take some time and your dependencies could have dependencies.</p>
<p>The other method I use is to skip the CPAN prompt and just directly execute the install of the module:</p>
<pre>perl -MCPAN -e 'install DateTime'</pre>
<p>This is just the most basic of usage, and there is probably a lot more you can do, but I have not had to use much more than this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/08/05/perl-cpan-installing-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gallery of Hello World!</title>
		<link>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/</link>
		<comments>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 15:14:39 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=324</guid>
		<description><![CDATA[Here is a list of the Hello World Programs for different languages: C #include int main() { printf("Hello World!"); } C++ #include int main() { cout &#60;&#60; "Hello World!" &#60;&#60; endl; } C# public class HelloWorld public static void Main() { System.Console.WriteLine("Hello World!"); } Java class HelloWorld { static void main(String[] args) { System.out.println("Hello World!"); [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a list of the Hello World Programs for different languages:</p>
<p>C</p>
<pre>#include
int main()
{
printf("Hello World!");
}</pre>
<p>C++</p>
<pre>#include
int main()
{
cout &lt;&lt; "Hello World!" &lt;&lt; endl;
}</pre>
<p>C#</p>
<pre>public class HelloWorld
  public static void Main()
  {
    System.Console.WriteLine("Hello World!");
  }</pre>
<p>Java</p>
<pre>class HelloWorld {
static void main(String[] args)
{
System.out.println("Hello World!");
}</pre>
<p>SHELL</p>
<pre>echo "Hello World"</pre>
<p>Python</p>
<pre>print "Hello World!\n"</pre>
<p>Ruby</p>
<pre>puts "Hello World!"</pre>
<p>Perl</p>
<pre>print "Hello World!\n";</pre>
<p>PHP</p>
<pre>  &lt;?php
    print "Hello World!";
  ?&gt;</pre>
<p>This is the simplest form of Hello World for most of these languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/08/04/gallery-of-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Exception java.lang.NoClassDefFoundError and how to resolve it</title>
		<link>http://www.etechtips.com/2011/01/26/java-exception-java-lang-noclassdeffounderror-and-how-to-resolve-it/</link>
		<comments>http://www.etechtips.com/2011/01/26/java-exception-java-lang-noclassdeffounderror-and-how-to-resolve-it/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 21:23:20 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=142</guid>
		<description><![CDATA[I had recently reinstalled my system and was trying to run a simple class that consisted of a &#8220;Hello World&#8221; program in Java. I received the following: Compile: $&#62; javac LottoMain.java Run: $&#62; java LottoMain Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: LottoMain Caused by: java.lang.ClassNotFoundException: LottoMain at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:319) at [...]]]></description>
			<content:encoded><![CDATA[<p>I had recently reinstalled my system and was trying to run a simple class that consisted<br />
of a &#8220;Hello World&#8221; program in Java.  I received the following:</p>
<p>Compile:</p>
<pre>$&gt; javac LottoMain.java</pre>
<p>Run:</p>
<pre>$&gt; java LottoMain</pre>
<p>Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: LottoMain<br />
Caused by: java.lang.ClassNotFoundException: LottoMain<br />
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)<br />
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)<br />
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)<br />
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)<br />
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)<br />
Could not find the main class: LottoMain. Program will exit.</p>
<p>The compile line completed without errrors and the LottoMain.class file was there, but<br />
what I didn&#8217;t know was that I no longer had the current directory &#8220;.&#8221; in my CLASSPATH variable.</p>
<p>After adding &#8220;.&#8221; to my CLASSPATH variable the run command gave me what I was expecting.</p>
<p>Run:</p>
<pre>$&gt; java LottoMain</pre>
<p>Hello Eric!</p>
<p>Updating the CLASSPATH variable in Bash:<br />
in my home directory/.bashrc file</p>
<pre>export CLASSPATH=$CLASSPATH:.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/01/26/java-exception-java-lang-noclassdeffounderror-and-how-to-resolve-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Variable Argument lists in functions for C and C++</title>
		<link>http://www.etechtips.com/2009/05/26/using-variable-argument-lists-in-functions-for-c/</link>
		<comments>http://www.etechtips.com/2009/05/26/using-variable-argument-lists-in-functions-for-c/#comments</comments>
		<pubDate>Wed, 27 May 2009 03:18:37 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://etechtips.com/?p=7</guid>
		<description><![CDATA[Using Variable Argument lists in functions for C\C++ In C there are times when you may want to have a variable amount of arguments passed into a function.  This can be accomplished when you pass the ellipses(&#8230;)  in as the last argument on your function.  The ellipses ,(&#8230;),  stands for zero  or more arguments. There [...]]]></description>
			<content:encoded><![CDATA[<p>Using Variable Argument lists in functions for C\C++</p>
<p>In C there are times when you may want to have a variable amount of arguments passed into a function.  This can be accomplished when you pass the ellipses(&#8230;)  in as the last argument on your function.  The ellipses ,(&#8230;),  stands for zero  or more arguments.<br />
There are a set of functions available to handle accessing this data and making it available to your function.</p>
<p>The source code example displays a version of the code for a printf like function and how to handle the optional arguments.</p>
<p>One note is that the arguments passed in to this function are not typed.  The handling of the argument depends on either a specific type passed in(ints only) or as is the case of the example, a formatted string to define the types of the arguments. What this means is that if you pass random sets of arguments, (such as ints, strings,chars, floats) there is no data type that is directly associated to the variable being passed in.</p>
<p>Required include file<br />
#include &lt;stdarg.h&gt;<br />
/* Old include &lt;varargs.h&gt; From before ISO C standard, GNU C compilers still support this */</p>
<p>Available functions:<br />
Macro: va_start(va_list , last-required argument)<br />
This sets up the pointer for va_list with the avaiable argument list.</p>
<p>Macro: va_arg(va_list, type)</p>
<p>This returns the value of the next argument and modifies the va_list argument<br />
to point to the subsequent(next) argument.  The type of the value returned by<br />
va_arg is type as specified in the call. type must be a self promoting type<br />
not char or short int) that matches the type of the actual argument.</p>
<p>Macro: va_end(va_list)</p>
<p>This ends the processing of the va_list element and subsequent va_arg calls<br />
may no longer work.  Note: In the GNU C library implementation this does nothing<br />
and is used for portability.</p>
<p>Sample Function Call:</p>
<pre><code>  int int1 = 1;

    char char1 = "s";

    char *str1 = "test";

    /* Sample function call. */
    ecdprintf("Int=%d Char=%c String=%s\n",int1,char1,str1);

Sample Code follows:

int ecdprintf(const char *pstr, ...)

{
    const char *lstr;
    va_list argp;
    int lint;
    char *lchar;
    char strarr[255];

    /* This is the start of vararg processing. The first argument is the
         container argument of the vararg list and the second argument
         is the last fixed parameter passed into the function. */

    va_start(argp, fmt);
    for(lstr = pstr; *lstr = '\0'; lstr++)
    {
        if (*lstr != '%')
        {
            putchar(*lstr);
            continue;
        }

        switch(*++lstr)
        {
            case 'd':
                i = va_arg(argp,int);
                s = itoa(i,strarr, 10);
                putchar(i);
                break;
            case 'c':
                i = va_arg(argp, int);
                putchar(i);
                break;
             case 's':
                 lchar = va_arg(argp,char *);
                 fputs(lchar,stdout);
                 break;
              case 'x':
                 i = va_arg(argp,int);
                 s = itoa(i, fmtbuf, 16);
                 fputs(lchar, stdout);
                 break;
               case '%':
                  putchar('%');
                  break;

               default:
                    break;

             }

    }

    va_end(argp);

    }

}
</code></pre>
<p>This example created the a simple printf like function using characters within the string to let the function know how to deal with the extra variables used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2009/05/26/using-variable-argument-lists-in-functions-for-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

