<?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>AmirWatad.com &#187; Programming</title>
	<atom:link href="http://www.amirwatad.com/blog/archives/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.amirwatad.com/blog</link>
	<description>Remember the name ;)</description>
	<lastBuildDate>Wed, 28 Jul 2010 17:15:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Array Indexing in C</title>
		<link>http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/</link>
		<comments>http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:04:33 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/</guid>
		<description><![CDATA[I found this interesting thing about array indexing in C somewhere in the web: Suppose that &#8220;a&#8221; is an array. Then, a[5] and 5[a] are quivallent. Both are interpreted as *(5 + a) or *(a + 5) which is the same Also: &#8220;Hello World&#8221;[3] and 3["Hello World"] are the same. Try and C --------- Note: [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/">Array Indexing in C</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I found this interesting thing about array indexing in C somewhere in the web:<br />
Suppose that &#8220;a&#8221; is an array. Then, a[5] and 5[a] are quivallent. Both are interpreted as *(5 + a) or *(a + 5) which is the same <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="Array Indexing in C" /> <br />
Also: &#8220;Hello World&#8221;[3] and 3["Hello World"] are the same. Try and C <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="Array Indexing in C" /> </p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/">Array Indexing in C</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=Array+Indexing+in+C+http://bit.ly/7TwvmP" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="Array Indexing in C" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/&amp;title=Array+Indexing+in+C" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="Array Indexing in C" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/&amp;title=Array+Indexing+in+C" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="Array Indexing in C" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/&amp;t=Array+Indexing+in+C" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="Array Indexing in C" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/&amp;title=Array+Indexing+in+C" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="Array Indexing in C" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/&amp;title=Array+Indexing+in+C" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="Array Indexing in C" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2010/01/06/array-indexing-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tools to Improve the Quality of Your Code</title>
		<link>http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/</link>
		<comments>http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 17:54:12 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code Quality]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=513</guid>
		<description><![CDATA[Just found a nice link at Wikipedia with a collection of tools to help analyzing the quality of your code. One interesting one is PMD (for Java), which is opensource. It statically analyses your code and alerts for potential problems. For C, there is splint (opensource as well), which statically analyses your code for potential [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/">Tools to Improve the Quality of Your Code</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Just found a nice link at Wikipedia with a collection of tools to help analyzing the quality of your code.</p>
<p>One interesting one is <a title="PMD" href="http://pmd.sourceforge.net/" target="_blank">PMD</a> (for Java), which is opensource. It statically analyses your code and alerts for potential problems.</p>
<p>For C, there is <a title="splint" href="http://splint.org/" target="_blank">splint</a> (opensource as well), which statically analyses your code for potential coding mistakes and security vulnerabilities.</p>
<p>The full list at Wikipedia is <a title="tools for static code analysis" href="http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis" target="_blank">here</a>.</p>
<p>Another great tool, which is not directly related to the above, is <a title="Valgrind" href="http://valgrind.org/" target="_blank">Valgrind</a>. While the above statically analyze your code (i.e., they find potential problems by &#8220;just looking at the code&#8221;), Valgrind is a tool for dynamic analysis, which means, it analyses the code by monitoring the way it runs. It can report possible memory leaks, possible deadlooks, and many other information. (The full tool suite description can be found <a title="Valgring tool suite" href="http://valgrind.org/info/tools.html" target="_blank">here</a>). The output of Valgrind is not very easy to read, but with a little practice one can feel more comfortable with it.</p>
<p>There is also a list of tools for dynamic analysis at Wikipedia. It&#8217;s located <a title="Dynamic code analysis - Wikipedia" href="http://en.wikipedia.org/wiki/Dynamic_code_analysis" target="_blank">here</a> and may be worths a glance.</p>
<p>Enjoy coding <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="Tools to Improve the Quality of Your Code" /> </p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/">Tools to Improve the Quality of Your Code</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=Tools+to+Improve+the+Quality+of+Your+Code+http://bit.ly/gq1NX" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="Tools to Improve the Quality of Your Code" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/&amp;title=Tools+to+Improve+the+Quality+of+Your+Code" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="Tools to Improve the Quality of Your Code" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/&amp;title=Tools+to+Improve+the+Quality+of+Your+Code" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="Tools to Improve the Quality of Your Code" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/&amp;t=Tools+to+Improve+the+Quality+of+Your+Code" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="Tools to Improve the Quality of Your Code" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/&amp;title=Tools+to+Improve+the+Quality+of+Your+Code" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="Tools to Improve the Quality of Your Code" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/&amp;title=Tools+to+Improve+the+Quality+of+Your+Code" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="Tools to Improve the Quality of Your Code" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2009/09/26/tools-to-improve-the-quality-of-your-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Bash Script to Convert brainfuck Code Into C</title>
		<link>http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/</link>
		<comments>http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 02:33:25 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=478</guid>
		<description><![CDATA[Brainfuck is a minimalist Turing Complete language. You can read about it here. The following bash script takes a file with brainfuck code (legal characters are > code.c Where code.bf is the file containing the brainfuck code. Here is the code: 1234567891011121314151617181920212223242526272829#!/bin/bash echo &#34;int main()&#34; echo &#34;{&#34; echo &#34;char pa[30000] = {0};&#34; echo &#34;char *p [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/">A Bash Script to Convert brainfuck Code Into C</a></p>
]]></description>
			<content:encoded><![CDATA[<p>
Brainfuck is a minimalist <a href="http://en.wikipedia.org/wiki/Turing_completeness">Turing Complete</a> language. You can read about it <a href="http://en.wikipedia.org/wiki/Brainfuck">here</a>.
</p>
<p></p>
<p>
The following bash script takes a file with brainfuck code (legal characters are <strong>><,.+-[]</strong> any other characters are ignored), and generates its C equivalent code, which can then be compiled with a C compiler and executed.
</p>
<p></p>
<p>
The output of this script lacks indentation. If you insist on having the C code indented you can achieve this by passing the output through a pipe to &#8220;indent&#8221;, &#8220;astyle&#8221; or similar programs.
</p>
<p></p>
<p>
The script should be called in the following way:</p>
<blockquote><p>./bf.sh code.bf > code.c </p></blockquote>
<p>Where code.bf is the file containing the brainfuck code.
</p>
<p>
<span id="more-478"></span><br />
</p>
<p>
Here is the code:
</p>
<p></p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;int main()&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;{&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;char pa[30000] = {0};&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;char *p = pa;&quot;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">#following this conversion table:</span><br />
<span style="color: #666666; font-style: italic;"># bf cmd&nbsp; &nbsp; | &nbsp; &nbsp;c equivalent</span><br />
<span style="color: #666666; font-style: italic;"># -----------------------------------</span><br />
<span style="color: #666666; font-style: italic;"># &gt; &nbsp; &nbsp; | &nbsp; ++p;</span><br />
<span style="color: #666666; font-style: italic;"># &lt; &nbsp; &nbsp; | &nbsp; --p;</span><br />
<span style="color: #666666; font-style: italic;"># + &nbsp; &nbsp; | &nbsp; ++*p;</span><br />
<span style="color: #666666; font-style: italic;"># - &nbsp; &nbsp; | &nbsp; --*p;</span><br />
<span style="color: #666666; font-style: italic;"># . &nbsp; &nbsp; | &nbsp; putchar(*p);</span><br />
<span style="color: #666666; font-style: italic;"># , &nbsp; &nbsp; | &nbsp; *p = getchar();</span><br />
<span style="color: #666666; font-style: italic;"># [ &nbsp; &nbsp; | &nbsp; while (*p) {</span><br />
<span style="color: #666666; font-style: italic;"># [ &nbsp; &nbsp; | &nbsp; }</span><br />
<span style="color: #666666; font-style: italic;">#-----------------------------------</span><br />
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[^]^[^&gt;&lt;,.+-]//g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/[^(&gt;&lt;\+\-\.\,\[\])]//g'</span> \<br />
<span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&gt;/\P\Pp;\n/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/&lt;/MMp;\n/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/\+/\+\+\*p;\n/g'</span> \<br />
<span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/-/--\*p;\n/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/\./putchar\(\*p\);\n/g'</span> \<br />
<span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/,/\*p = getchar\(\);\n/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/\[/while \(\*p\) {\n/g'</span> \<br />
<span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/]/}\n/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/P/\+/g'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/M/-/g'</span> <span style="color: #ff0000;">&quot;$1&quot;</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;return 0;&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;}&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>;</div></td></tr></tbody></table></div>
<p></p>
<p>
You can also download it here: <a href="http://www.amirwatad.com/blog/downloads/Brainfuck+to+C+converter" title="Downloaded 189 times"><img src="http://www.amirwatad.com/blog/wp-content/plugins/download-monitor/img/download.gif" alt="Brainfuck to C converter 672 bytes" title="Brainfuck to C converter 672 bytes" width=100 heigh=3 /></a><br />
<br />
Make it executable (chmod +x bf.sh) and you&#8217;re ready to go.
</p>
<p></p>
<p>
For examples of brainfuck programs see the <a href="http://en.wikipedia.org/wiki/Brainfuck">article at Wikipedia</a>.<br />
<br />
Enjoy <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="A Bash Script to Convert brainfuck Code Into C" /> </p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/">A Bash Script to Convert brainfuck Code Into C</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=A+Bash+Script+to+Convert+brainfuck+Code+Into+C+http://bit.ly/smXIE" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="A Bash Script to Convert brainfuck Code Into C" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/&amp;title=A+Bash+Script+to+Convert+brainfuck+Code+Into+C" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="A Bash Script to Convert brainfuck Code Into C" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/&amp;title=A+Bash+Script+to+Convert+brainfuck+Code+Into+C" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="A Bash Script to Convert brainfuck Code Into C" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/&amp;t=A+Bash+Script+to+Convert+brainfuck+Code+Into+C" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="A Bash Script to Convert brainfuck Code Into C" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/&amp;title=A+Bash+Script+to+Convert+brainfuck+Code+Into+C" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="A Bash Script to Convert brainfuck Code Into C" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/&amp;title=A+Bash+Script+to+Convert+brainfuck+Code+Into+C" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="A Bash Script to Convert brainfuck Code Into C" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2009/06/14/a-bash-script-to-convert-brainfuck-code-into-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Share Code Snippets Easily From the Command Line</title>
		<link>http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/</link>
		<comments>http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 22:15:49 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line Interface]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Sharing]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=475</guid>
		<description><![CDATA[This is a great tip I found at commandlinefu to easily share code snippets write from the command line. First, you may want to add this to your aliases file: 1alias share='curl -F &#34;sprunge=&#60;-&#34; http://sprunge.us &#124; xclip' (If you don&#8217;t have the xclip program, you can easily install it from your package manager.) Now, say [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/">Share Code Snippets Easily From the Command Line</a></p>
]]></description>
			<content:encoded><![CDATA[<p>
This is a great tip I found at <a href="http://www.commandlinefu.com/commands/view/2368/run-a-command-store-the-output-in-a-pastebin-on-the-internet-and-place-the-url-on-the-xclipboard">commandlinefu</a> to easily share code snippets write from the command line.
 </p>
<p></p>
<p>
First, you may want to add this to your aliases file:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">share</span>=<span style="color: #ff0000;">'curl -F &quot;sprunge=&lt;-&quot; http://sprunge.us | xclip'</span></div></td></tr></tbody></table></div>
<p>(If you don&#8217;t have the xclip program, you can easily install it from your package manager.)
</p>
<p></p>
<p>
Now, say that you have a c program named &#8220;hello.c&#8221;, to share it, type this (after reloading your aliases file of course):</p>
<blockquote><p>
cat hello.c | share
</p></blockquote>
<p>
Now, the code is already in the internet, and the URL is in your clipboard. Go to firefox and click the middle mouse button in the URI area. You&#8217;ll see a URL similar to this:</p>
<blockquote><p>

http://sprunge.us/BaFS

</p></blockquote>
<p><br/><br />
To view the code with syntax highlighting and line numbers, just append &#8220;?c? (or &#8220;?lang&#8221; where &#8216;lang&#8217; is the relevant programming language). So the final URL should look like this:</p>
<blockquote><p>

http://sprunge.us/BaFS?c

</p></blockquote>
<p></p>
<p>
Enjoy <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="Share Code Snippets Easily From the Command Line" /> </p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/">Share Code Snippets Easily From the Command Line</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=Share+Code+Snippets+Easily+From+the+Command+Line+http://bit.ly/COL7f" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="Share Code Snippets Easily From the Command Line" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/&amp;title=Share+Code+Snippets+Easily+From+the+Command+Line" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="Share Code Snippets Easily From the Command Line" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/&amp;title=Share+Code+Snippets+Easily+From+the+Command+Line" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="Share Code Snippets Easily From the Command Line" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/&amp;t=Share+Code+Snippets+Easily+From+the+Command+Line" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="Share Code Snippets Easily From the Command Line" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/&amp;title=Share+Code+Snippets+Easily+From+the+Command+Line" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="Share Code Snippets Easily From the Command Line" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/&amp;title=Share+Code+Snippets+Easily+From+the+Command+Line" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="Share Code Snippets Easily From the Command Line" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2009/06/13/share-code-snippets-easily-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending Emails with Matlab</title>
		<link>http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/</link>
		<comments>http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 01:57:30 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Matlab]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=224</guid>
		<description><![CDATA[This method is (as far as I know) not found in the official Matlab&#8217;s documentation.  I found it a long time ago somewhere in the internet (don&#8217;t remember where, sorry). It&#8217;s intended for sending Emails using Matlab. In order to use it, you should have an Email account which supports SMTP (eg. Gmail). This account [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/">Sending Emails with Matlab</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This method is (as far as I know) not found in the official Matlab&#8217;s documentation.  I found it a long time ago somewhere in the internet (don&#8217;t remember where, sorry). It&#8217;s intended for sending Emails using Matlab.</p>
<p>In order to use it, you should have an Email account which supports SMTP (eg. Gmail). This account will be the account we&#8217;re sending the messages through.</p>
<p>The script assumes you&#8217;re using Gmail, but it can be easily modified to use other Email suppliers (are there any?)</p>
<p><span id="more-224"></span></p>
<p>Here is the script, it&#8217;s a matlab function:</p>
<pre>
<div class="codecolorer-container matlab twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="matlab codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">function</span> send_mail<span style="color: #080;">&#40;</span>recipients, subject, mail_message, attachments<span style="color: #080;">&#41;</span><br />
<span style="color: #228B22;">% send_mail sends a mail message through Gmail</span><br />
<span style="color: #228B22;">% function send_mail(subject, recipients, mail_message, attachments)</span><br />
<span style="color: #228B22;">% input arguments:</span><br />
<span style="color: #228B22;">% subject: A string - subject of the mail</span><br />
<span style="color: #228B22;">% recipents: A cell array of strings - Email addresses of recipients</span><br />
<span style="color: #228B22;">% &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eg. {'mail1@mail.com', 'mail2@mail.com'}</span><br />
<span style="color: #228B22;">% mail_message: A cell array of strings - Actual body of the message A cell per line.</span><br />
<span style="color: #228B22;">% attachments: A cell array of string - A cell per attachment: path to a file to attach Email.</span><br />
<span style="color: #228B22;">% &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Use [] for none.</span><br />
<span style="color: #228B22;">% Define these:</span><br />
mail = <span style="color:#A020F0;">'myemail@gmail.com'</span>; <span style="color: #228B22;">%Your GMail email address</span><br />
password = <span style="color:#A020F0;">'mypassword'</span>; <span style="color: #228B22;">%Your GMail password</span><br />
<span style="color: #228B22;">% Don't touch unless you need to change the Email supplier (currently Gmail)</span><br />
setpref<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Internet'</span>,<span style="color:#A020F0;">'E_mail'</span>,mail<span style="color: #080;">&#41;</span>;<br />
setpref<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Internet'</span>,<span style="color:#A020F0;">'SMTP_Server'</span>,<span style="color:#A020F0;">'smtp.gmail.com'</span><span style="color: #080;">&#41;</span>;<br />
setpref<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Internet'</span>,<span style="color:#A020F0;">'SMTP_Username'</span>,mail<span style="color: #080;">&#41;</span>;<br />
setpref<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Internet'</span>,<span style="color:#A020F0;">'SMTP_Password'</span>,password<span style="color: #080;">&#41;</span>;<br />
props = java.<span style="">lang</span>.<span style="">System</span>.<span style="">getProperties</span>;<br />
props.<span style="">setProperty</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'mail.smtp.auth'</span>,<span style="color:#A020F0;">'true'</span><span style="color: #080;">&#41;</span>;<br />
props.<span style="">setProperty</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'mail.smtp.socketFactory.class'</span>, <span style="color:#A020F0;">'javax.net.ssl.SSLSocketFactory'</span><span style="color: #080;">&#41;</span>;<br />
props.<span style="">setProperty</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'mail.smtp.socketFactory.port'</span>,<span style="color:#A020F0;">'465'</span><span style="color: #080;">&#41;</span>;<br />
<span style="color: #228B22;">% Send the email</span><br />
sendmail<span style="color: #080;">&#40;</span>recipients, subject, mail_message, attachments<span style="color: #080;">&#41;</span>;</div></td></tr></tbody></table></div>
</pre>
<p><br class="spacer_" /></p>
<p>And it can be called this way:</p>
<pre>
<div class="codecolorer-container matlab twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="matlab codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">send_to = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'friend@somesupplier.com'</span><span style="color: #080;">&#125;</span>;<br />
subject = <span style="color:#A020F0;">'hello'</span>;<br />
message = <span style="color: #080;">&#123;</span><span style="color: #080;">...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#A020F0;">'hi dear!'</span>,<span style="color: #080;">...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#A020F0;">'Just wanted to tell you what I think about you'</span>,<span style="color: #080;">...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#A020F0;">'I HATE YOU!'</span>,<span style="color: #080;">...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#A020F0;">'Not really :)'</span>,<span style="color: #080;">...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#A020F0;">'Ah, see the attached pictures'</span><span style="color: #080;">...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #080;">&#125;</span>;<br />
mypic1 = <span style="color:#A020F0;">'../pictures/blabla/picture1.png'</span>;<br />
mypic2 = <span style="color:#A020F0;">'../pictures/blabla/picture2.png'</span>;<br />
send_mail<span style="color: #080;">&#40;</span>send_to, subject, message, <span style="color: #080;">&#123;</span>mypic1, mypic2<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</div></td></tr></tbody></table></div>
</pre>
<p><br class="spacer_" /></p>
<p>Notice that the username/password are hardcoded. If you&#8217;re concerned about this, you can pass them as arguments to the function. However, this way you&#8217;ll hide them from inside the function, but they&#8217;ll appear somewhere in the caller code.</p>
<p>Another method is generating the &#8220;pcode&#8221; (See Matlab&#8217;s help about pcode). In general, it&#8217;s an encrypted version of the M-file, which can be interpreted by Matlab, but cannot be read by others. I believe that this is the appropriate method in our case. Once you have the pcode, you don&#8217;t need the M-code anymore, and nobody can see your password.  (you can save a m-code version without the password/username inside it for later use if you want).</p>
<p>When I first tested this script, I called it from a 50-iterations for loop, sending the same Email to the same person 50 times (it included a figure from Matlab). Please don&#8217;t be like me since it&#8217;s an abuse of the script/Gmail, and I believe it&#8217;s a violation of Gmails TOS. You might end with your account disabled or blacklisted. So please use it wisely.</p>
<p>
Thats it <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="Sending Emails with Matlab" /> </p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/">Sending Emails with Matlab</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=Sending+Emails+with+Matlab+http://bit.ly/m8Hrt" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="Sending Emails with Matlab" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/&amp;title=Sending+Emails+with+Matlab" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="Sending Emails with Matlab" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/&amp;title=Sending+Emails+with+Matlab" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="Sending Emails with Matlab" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/&amp;t=Sending+Emails+with+Matlab" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="Sending Emails with Matlab" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/&amp;title=Sending+Emails+with+Matlab" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="Sending Emails with Matlab" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/&amp;title=Sending+Emails+with+Matlab" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="Sending Emails with Matlab" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2009/01/31/sending-emails-with-matlab/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Convert a Number into a String in C++</title>
		<link>http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/</link>
		<comments>http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 18:04:11 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=198</guid>
		<description><![CDATA[I found a few ways to convert a number into C++, some of them are C style (like using sprintf), and some are ugly (i.e non-standard, like using itoa), and there some nice way which uses string streams to achieve this. Where going to define and implement a function called Stringify, which accepts an integer [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/">How to Convert a Number into a String in C++</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I found a few ways to convert a number into C++, some of them are C style (like using sprintf), and some are ugly (i.e non-standard, like using itoa), and there some nice way which uses string streams to achieve this.</p>
<p>Where going to define and implement a function called Stringify, which accepts an integer and returns a string (this can be extended to accept any numeric value).</p>
<p><span id="more-198"></span></p>
<p>Here is a C++ code, which implements this function, and uses it in a simple example.</p>
<pre>
<div class="codecolorer-container cpp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339900;">#include &lt;iostream&gt;</span><br />
<span style="color: #339900;">#include &lt;string&gt;</span><br />
<span style="color: #339900;">#include &nbsp;&lt;sstream&gt;</span><br />
<br />
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span><br />
<br />
string<br />
Stringify<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> number<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ostringstream tmpStr<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; tmpStr <span style="color: #000080;">&lt;&lt;</span> number<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span><span style="color: #008000;">&#40;</span>tmpStr.<span style="color: #007788;">str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">int</span><br />
main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">42</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; string y <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;x = &quot;</span> <span style="color: #000040;">+</span> Stringify<span style="color: #008000;">&#40;</span>x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> y <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
</pre>
<p>Notice that we included iostream so we can use cout, and sstream so we can use string streams. We also need to include string since we&#8217;re dealing with strings.</p>
<p>Hope that this is useful for somebody <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="How to Convert a Number into a String in C++" /> </p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/">How to Convert a Number into a String in C++</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=How+to+Convert+a+Number+into+a+String+in+C%2B%2B+http://bit.ly/UeF00" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="How to Convert a Number into a String in C++" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/&amp;title=How+to+Convert+a+Number+into+a+String+in+C%2B%2B" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="How to Convert a Number into a String in C++" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/&amp;title=How+to+Convert+a+Number+into+a+String+in+C%2B%2B" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="How to Convert a Number into a String in C++" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/&amp;t=How+to+Convert+a+Number+into+a+String+in+C%2B%2B" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="How to Convert a Number into a String in C++" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/&amp;title=How+to+Convert+a+Number+into+a+String+in+C%2B%2B" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="How to Convert a Number into a String in C++" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/&amp;title=How+to+Convert+a+Number+into+a+String+in+C%2B%2B" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="How to Convert a Number into a String in C++" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2009/01/23/how-to-convert-a-number-into-a-string-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Power of Polymorphism (Video)</title>
		<link>http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/</link>
		<comments>http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 13:22:35 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=153</guid>
		<description><![CDATA[This video is part of &#8220;The Clean Code Talks&#8221; series, which is itself a part of the great &#8220;Google TechTalks&#8221;. The video shows the strength of using polymorphism instead of switch statements and &#8220;if&#8221; conditionals, to get a much cleaner cleaner code, allowing it to be more readable, testable and maintainable. One of the best [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/">The Power of Polymorphism (Video)</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This video is part of &#8220;The Clean Code Talks&#8221; series, which is itself a part of the great &#8220;Google TechTalks&#8221;.</p>
<p>The video shows the strength of using polymorphism instead of switch statements and &#8220;if&#8221; conditionals, to get a much cleaner cleaner code, allowing it to be more readable, testable and maintainable.</p>
<p>One of the best videos I watched in this series.</p>
<p><span id="more-153"></span></p>
<p><span class="youtube">
<object type="application/x-shockwave-flash" width="640" height="530" data="http://www.youtube.com/v/4F72VULWFvc&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1">
<param name="movie" value="http://www.youtube.com/v/4F72VULWFvc&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0?rel=1" />
<param name="allowFullScreen" value="true" />
<param name="wmode" value="transparent" />
</object>
</span><p><a href="http://www.youtube.com/watch?v=4F72VULWFvc">www.youtube.com/watch?v=4F72VULWFvc</a></p></p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/">The Power of Polymorphism (Video)</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=The+Power+of+Polymorphism+%28Video%29+http://bit.ly/92Fzk" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="The Power of Polymorphism (Video)" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/&amp;title=The+Power+of+Polymorphism+%28Video%29" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="The Power of Polymorphism (Video)" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/&amp;title=The+Power+of+Polymorphism+%28Video%29" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="The Power of Polymorphism (Video)" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/&amp;t=The+Power+of+Polymorphism+%28Video%29" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="The Power of Polymorphism (Video)" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/&amp;title=The+Power+of+Polymorphism+%28Video%29" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="The Power of Polymorphism (Video)" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/&amp;title=The+Power+of+Polymorphism+%28Video%29" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="The Power of Polymorphism (Video)" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2008/12/15/the-power-of-polymorphism-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily Create Code Snippets with Bonetree Box</title>
		<link>http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/</link>
		<comments>http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 23:46:02 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=123</guid>
		<description><![CDATA[Update: Looks like the link is not valid anymore    Anyhow, one always can use http://pastebin.com Have you ever needed to show a code to a friend? If yes, I have no doubt that you will love Bonetree Box. This web tool has a very simple and well-designed interface, and working with it is with [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/">Easily Create Code Snippets with Bonetree Box</a></p>
]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;"><span style="color: #ff0000;">Update: Looks like the link is not valid anymore <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' title="Easily Create Code Snippets with Bonetree Box" />    Anyhow, one always can use <a title="pastebin.com" href="http://pastebin.com" target="_blank">http://pastebin.com</a> <img src='http://www.amirwatad.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' title="Easily Create Code Snippets with Bonetree Box" /> </span><br />
</span></p>
<p>Have you ever needed to show a code to a friend? If yes, I have no doubt that you will love Bonetree Box.</p>
<p>This web tool has a very simple and well-designed interface, and working with it is with no doubt a pleasant experience.</p>
<p>The tool has support for a set of popular programming languages, such as C, C++, Bash and more (I believe that this set will be extended over time), and allows you to create a syntax highlighted code snippets with zero effort.</p>
<p><span id="more-123"></span></p>
<p>Ah, I almost forgot to mention that this tool supports the usage of TAB for syntax indentation (Which is not a so trivial feature if you think about it).</p>
<p>After writing your code in a textbox, passing the CAPTCHA and clicking the &#8220;save&#8221; button, you&#8217;ll get a link to your code snippet, which is valid for 5 days and resides in a neat, minimalistic and good-looking page.</p>
<p>Now you can pass the link to whoever you want.</p>
<p>Below is a screenshot of how the code snippet looks like:</p>
<div id="attachment_124" class="wp-caption alignnone" style="width: 310px"><a href="http://www.amirwatad.com/blog/wp-content/uploads/2008/11/screenshot29_11_08_01_36_30_839983803.png"><img class="size-medium wp-image-124" title="bonetree box code snippet" src="http://www.amirwatad.com/blog/wp-content/uploads/2008/11/screenshot29_11_08_01_36_30_839983803-300x174.png" alt="bonetree box code snippet" width="300" height="174" /></a><p class="wp-caption-text">Click the image for a larger version</p></div>
<p><br class="spacer_" /></p>
<p>Go try it yourself: http://box.bonetree.net/</p>
<p><br class="spacer_" /></p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/">Easily Create Code Snippets with Bonetree Box</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=Easily+Create+Code+Snippets+with+Bonetree+Box+http://bit.ly/PtzLC" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="Easily Create Code Snippets with Bonetree Box" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/&amp;title=Easily+Create+Code+Snippets+with+Bonetree+Box" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="Easily Create Code Snippets with Bonetree Box" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/&amp;title=Easily+Create+Code+Snippets+with+Bonetree+Box" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="Easily Create Code Snippets with Bonetree Box" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/&amp;t=Easily+Create+Code+Snippets+with+Bonetree+Box" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="Easily Create Code Snippets with Bonetree Box" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/&amp;title=Easily+Create+Code+Snippets+with+Bonetree+Box" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="Easily Create Code Snippets with Bonetree Box" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/&amp;title=Easily+Create+Code+Snippets+with+Bonetree+Box" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="Easily Create Code Snippets with Bonetree Box" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2008/11/29/easily-create-code-snippets-with-bonetree-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Declare an Array of Strings in C</title>
		<link>http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/</link>
		<comments>http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 23:57:40 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=105</guid>
		<description><![CDATA[Ok, I know this is not a big deal, I just hate to deal with strings in C, so I&#8217;ll put the code here so I can copy-paste-modify whenever I need to do such things. Purpose: declare an array of strings. There are two cases here: First case: You know the number of strings (say [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/">How to Declare an Array of Strings in C</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Ok, I know this is not a big deal, I just hate to deal with strings in C, so I&#8217;ll put the code here so I can copy-paste-modify whenever I need to do such things.</p>
<p>Purpose: declare an array of strings.</p>
<p>There are two cases here:</p>
<p><span id="more-105"></span></p>
<p>First case: You know the number of strings (say NUM_OF_STRINGS), and all strings have the same length &#8211; including the terminating &#8216;\0&#8242; character &#8211; (say LENGTH_OF_STRING).</p>
<p>In this case, this is how the array can be declared:</p>
<pre>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">char</span><span style="color: #339933;">*</span> arrayOfStrings<span style="color: #009900;">&#91;</span>NUM_OF_STRINGS<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> NUM_OF_STRINGS<span style="color: #339933;">;</span> i <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #009900;">&#40;</span>arrayOfStrings<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>LENGTH_OF_STRING <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</pre>
<p>Second case: Number of strings and length of each string is know only in runtime. In this case your code should look like this:</p>
<pre>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">char</span><span style="color: #339933;">**</span> arrayOfStrings<span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> nStrings <span style="color: #339933;">=</span> GetNumberOfStrings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #009900;">&#40;</span>arrayOfStrings <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">**</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>nStrings <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exit<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> nStrings<span style="color: #339933;">;</span> i <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> strLen <span style="color: #339933;">=</span> GetStringLength<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* Length includes terminating '\0' char */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #009900;">&#40;</span>arrayOfStrings<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>strLen <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</pre>
<p>That&#8217;s it. Don&#8217;t forget to free the allocated memory when you&#8217;re done.</p>
<p><br class="spacer_" /></p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/">How to Declare an Array of Strings in C</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=How+to+Declare+an+Array+of+Strings+in+C+http://bit.ly/YIn4" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="How to Declare an Array of Strings in C" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/&amp;title=How+to+Declare+an+Array+of+Strings+in+C" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="How to Declare an Array of Strings in C" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/&amp;title=How+to+Declare+an+Array+of+Strings+in+C" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="How to Declare an Array of Strings in C" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/&amp;t=How+to+Declare+an+Array+of+Strings+in+C" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="How to Declare an Array of Strings in C" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/&amp;title=How+to+Declare+an+Array+of+Strings+in+C" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="How to Declare an Array of Strings in C" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/&amp;title=How+to+Declare+an+Array+of+Strings+in+C" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="How to Declare an Array of Strings in C" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2008/11/28/how-to-declare-an-array-of-strings-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Macros to Print Debug Messages in C</title>
		<link>http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/</link>
		<comments>http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 13:07:55 +0000</pubDate>
		<dc:creator>Amir Watad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Macros]]></category>

		<guid isPermaLink="false">http://www.amirwatad.com/blog/?p=83</guid>
		<description><![CDATA[I have to confess: It&#8217;s my first time using macros for debug, I used to just add printf-s when developing and remove them when the code is ready &#8211; Which is and ugly and very unprofessional in my opinion. So, I decided to start caring about how my code looks, even in development stage. Here [...]<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/">Using Macros to Print Debug Messages in C</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I have to confess: It&#8217;s my first time using macros for debug, I used to just add printf-s when developing and remove them when the code is ready &#8211; Which is and ugly and very unprofessional in my opinion.</p>
<p>So, I decided to start caring about how my code looks, even in development stage. Here how I use macros for debug messages. (I needed the help of a <a title="LIUB.com" href="http://www.liub.com" target="_blank">friend</a> to get this work).</p>
<p>first of all, define this:</p>
<p><span id="more-83"></span></p>
<pre>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define DEBUG</span><br />
<br />
<span style="color: #339933;">#ifdef DEBUG</span><br />
<span style="color: #339933;">#define PRINT_DEBUG(format, args...) printf(&quot;\033[31m&quot;format&quot;\033[0m&quot;, ##args);</span><br />
<span style="color: #339933;">#else</span><br />
<span style="color: #339933;">#define PRINT_DEBUG(format, args...)</span><br />
<span style="color: #339933;">#endif</span></div></td></tr></tbody></table></div>
</pre>
<p>(The &#8220;strange&#8221; \033[31m characters tell the shell to print messages in Red, <a title="Printing Color in Linux" href="http://www.amirwatad.com/blog/archives/2008/08/07/printing-with-color-to-linux-console/" target="_blank">see my previous post about printing color in Linux</a>)</p>
<p>Now, in your code, to print a debug message, just write something like this:</p>
<pre>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PRINT_DEBUG<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;This is a Debug Message: x+y = %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> x<span style="color: #339933;">+</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</pre>
<p>When you&#8217;re done developing, just remove the <strong>#define DEBUG</strong> from your code, and you&#8217;re done, no debug messages, and your program&#8217;s output is clean.</p>
<p><br class="spacer_" /></p>
<p>---------
Note:
Some RSS readers might display this post with incorrect format.
View original post at <a href="http://www.amirwatad.com/blog">AmirWatad.com </a><br/><br/><a href="http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/">Using Macros to Print Debug Messages in C</a></p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=Using+Macros+to+Print+Debug+Messages+in+C+http://bit.ly/BDfdG" title="Post to Twitter"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big3.png" alt="Post to Twitter" title="Using Macros to Print Debug Messages in C" /></a> <a target="_blank" class="tt" href="http://delicious.com/post?url=http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/&amp;title=Using+Macros+to+Print+Debug+Messages+in+C" title="Post to Delicious"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious-big3.png" alt="Post to Delicious" title="Using Macros to Print Debug Messages in C" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/&amp;title=Using+Macros+to+Print+Debug+Messages+in+C" title="Post to Digg"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-digg-big3.png" alt="Post to Digg" title="Using Macros to Print Debug Messages in C" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/&amp;t=Using+Macros+to+Print+Debug+Messages+in+C" title="Post to Facebook"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-facebook-big3.png" alt="Post to Facebook" title="Using Macros to Print Debug Messages in C" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/&amp;title=Using+Macros+to+Print+Debug+Messages+in+C" title="Post to Reddit"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit-big3.png" alt="Post to Reddit" title="Using Macros to Print Debug Messages in C" /></a> <a target="_blank" class="tt" href="http://stumbleupon.com/submit?url=http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/&amp;title=Using+Macros+to+Print+Debug+Messages+in+C" title="Post to StumbleUpon"><img class="nothumb" src="http://www.amirwatad.com/blog/wp-content/plugins/tweet-this/icons/tt-su-big3.png" alt="Post to StumbleUpon" title="Using Macros to Print Debug Messages in C" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.amirwatad.com/blog/archives/2008/11/22/using-macros-to-print-debug-messages-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.188 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-07-30 20:52:01 -->
