<?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; C/C++</title>
	<atom:link href="http://www.etechtips.com/tag/cc/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>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>

