<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-820837548505128567</id><updated>2011-12-30T21:56:00.743+05:00</updated><category term='Automated Testing'/><category term='Software Utilities'/><category term='C/C++ interview questions'/><category term='friend function'/><category term='std::vector'/><category term='Microsoft'/><category term='std::string'/><category term='C'/><category term='callback funtion'/><category term='free'/><category term='.Net'/><category term='Junk characters in recv return'/><category term='String'/><category term='function pointer'/><category term='Modern Computing'/><category term='Software Framework'/><category term='TCP/IP'/><category term='Web'/><category term='C++'/><category term='Standard Template Library'/><category term='DirectoryServices'/><category term='un-initialized parameters'/><category term='Char**'/><category term='Framework'/><category term='printrf'/><category term='web service'/><category term='MCPD'/><category term='Smart Phone Programming'/><category term='pure virtual funtion'/><category term='web-method'/><category term='out parameters'/><category term='web method'/><category term='Network Programming'/><category term='copy constructor'/><category term='NULL'/><category term='std::map'/><category term='C/C++'/><category term='Accept method'/><category term='Code-Aerobics'/><category term='Java'/><category term='API'/><category term='web-service'/><category term='C#'/><category term='PHP'/><category term='Microsoft Certification'/><category term='hyperlink'/><category term='malloc'/><category term='substring'/><category term='Joomla'/><category term='STL'/><category term='Win32 Sockets'/><category term='MCTS'/><category term='virtual destructor'/><title type='text'>A Programmer's Day</title><subtitle type='html'>Things that I have experienced as a programmer...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-106426487238497650</id><published>2011-11-11T09:49:00.001+05:00</published><updated>2011-11-11T13:20:35.366+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Smart Phone Programming'/><title type='text'>What makes Android Programming Simpler and iOS difficult?</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img alt="ios-5-android-ice-cream-sandwich-apple-google" border="0" height="306" src="http://3.bp.blogspot.com/-6mmUEtm5ozw/TrzB9mBuCCI/AAAAAAAABO8/YfvGPot0u20/s400/ios-5-android-ice-cream-sandwich-apple-google.jpg" width="400" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;I cannot start writing iPhone and iPad software because?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I don't have an Apple... No! don't bring me a KG of fresh red apples please, I am referring to the Apple which is a computer. It's impossible to code stuff up without an Apple machine, even for sake of learning. Apple MUST create a tool chain for people running Windows as we know it's the most widely used operating system, just like the iPhone which is a crazily used "Somewhat Smart" Phone. They could create a development environment, and a few emulators to get new going with iOS development. I believe it would cost less than $100k to develop such a solution, maintenance cost won't go beyond this as well.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;b&gt;I can start writing Android software because?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Because the tool chain is available for Windows, and Linux as well. We got things like Eclipse and ADT, that make producing Android software very easy. Anybody and everybody with little knowledge and some enthusiasm can jump into it.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;&lt;b&gt;For fresh grads, Android is easy but iOS is difficult because?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Fresh grads are usually scared of new programming languages, basically the PHD and MPhild wielding "theoretical giants" that are dominating the universities cultivate the fear. They are the people(almost always) not good at programming, but super fast at publishing papers and attempting exams; and that is precisely why they can't find jobs in practical code writing/analysis/management positions in industry and seek refuge(read occupy) universities. These people scare the youth away from real life programming, by over-explanation of simple constructs like if/for/while.&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/-hCisISlLsWw/TrzCgKMcU3I/AAAAAAAABPE/zBkk5GQKe5Y/s1600/Java-language-android.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img alt="Java-language-android" border="0" src="http://2.bp.blogspot.com/-hCisISlLsWw/TrzCgKMcU3I/AAAAAAAABPE/zBkk5GQKe5Y/s1600/Java-language-android.jpg" /&gt;&lt;/a&gt;Objective C is certainly not the most popular academic language, Java on the other hand is being taught in thousands of Universities around the world. C is usually the first programming language and Java comes afterwards, but there are cases when they take directly off from Java.&lt;br /&gt;The point is, adopting to Android platform's Java based program writing is very easy for fresh grads on the other hand Objective-C centric iOS programming is relatively difficult to adapt.&lt;br /&gt;&lt;br /&gt;Solutions for developing iPhone apps without a Mac are available but the seem to even complicate the process. We got options like "WebView", JavaScript and HTML 5 based widgets or applications that can run on any mobile platform (Android, iOS, WP7). But if you want to leverage the platform specific benefits, again you must mess with Obective-C or Java.&lt;br /&gt;&lt;br /&gt;I deliberately left Windows Phone 7 or 7.5 because this debate is not concerned with Microsoft's lagging smart phone platform. Microsoft VB.Net, C# .Net are being taught in a very little amount of universities, although people learn these languages once they complete graduation. But still Microsoft is far behind from Apple and Google in Smart Phone computing and these two are the real competitors for the throne of Mobile/Tablet computing.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/-K9ENu5Lf9fg/TrzC88nVUCI/AAAAAAAABPM/kMlwVxQOTcQ/s1600/objective-c-ios-apple.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img alt="objective-c-ios-apple" border="0" src="http://4.bp.blogspot.com/-K9ENu5Lf9fg/TrzC88nVUCI/AAAAAAAABPM/kMlwVxQOTcQ/s1600/objective-c-ios-apple.png" /&gt;&lt;/a&gt;Microsoft's like a mammoth right now, it's got a lot of software(Desktop/Server OS, CMS, Databases, Application Framework etc.) in its repertoire, a huge and stable customer base, but still it's unable to produce a truly strong iOS/Android rival. HTC is supposed to offer a smart phone with Quad Core Nvidia Tegra 3 processor by the end of this year or earlier next year, but Windows Phone will not get even a dual core processor by late 2012.&lt;br /&gt;Blackberry is another platform Java coders can head to, but the BB show seems to be coming to an end. And most probably they'll shelve their OS (BB OS7) and cancel QNX program, and move to Windows Phone joining the club Nokia earlier this year joined.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-106426487238497650?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/106426487238497650/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/11/what-makes-android-programming-simpler.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/106426487238497650'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/106426487238497650'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/11/what-makes-android-programming-simpler.html' title='What makes Android Programming Simpler and iOS difficult?'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-6mmUEtm5ozw/TrzB9mBuCCI/AAAAAAAABO8/YfvGPot0u20/s72-c/ios-5-android-ice-cream-sandwich-apple-google.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-3765236726178038724</id><published>2011-10-07T19:26:00.000+05:00</published><updated>2011-11-11T13:19:42.487+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>C# string utility functions containsAtLeastOneChar-containsOnlySpecifiedSpecChars-excludesSimilar</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;img alt="c-sharp-green" border="0" src="http://4.bp.blogspot.com/-3N4iDxoKYm4/TrtjLaU2DjI/AAAAAAAABOY/syqbeIh8Qv4/s1600/c-sharp-green.png" /&gt;&lt;/div&gt;&lt;br /&gt;A utility class to perform simple operations on strings using C#. The logic is simple, one can transform the code given below to C++, PHP, or JavaScript within 2 minutes. I know each one of the programming languages I mentioned here, and all other first class modern programming languages have got sophisticated regular expression packages. But, the use of regex is not an option for everyone. Some got the skill to learn, but just don't have the time needed to read docs. Some don't want to import in a full blown namespace like System.Text.RegularExpressions&lt;br /&gt;And some other are plain lazy.&lt;br /&gt;Here goes the code, the names are descriptive enough, first one&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;containsAtLeastOneChar&amp;nbsp;&lt;/span&gt;&amp;nbsp;checks whether a string contains at least one character of a certain character set. For example, we want to check whether a password generated by a automatic password generator contains at least one capital letter, one number, and one special character.&lt;br /&gt;Second one,&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;containsOnlySpecifiedSpecChars &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;returns true when the supplied string conains only specified characters.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Third function&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;excludesSimilar&lt;/span&gt;&amp;nbsp;will return true when a string does not contain repeating characters.&lt;br /&gt;The class &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Commons &lt;/span&gt;contains static member variables, you could try passing these values to the static member functions of this class and experiment &amp;nbsp;around to check the results. It will also save you some typing :)&lt;br /&gt;You could just copy paste the code given below as it is, it's supposed to work.&lt;br /&gt;Happy coding!&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;div style="background-color: #cccccc;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public class &lt;/span&gt;Commons&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static bool&lt;/span&gt; containsAtLeastOneChar(&lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strWord, &lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strCompairTo)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&amp;nbsp;int &lt;/span&gt;nIdx = -1;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&amp;nbsp;foreach &lt;/span&gt;(&lt;span class="Apple-style-span" style="color: blue;"&gt;char &lt;/span&gt;c &lt;span class="Apple-style-span" style="color: blue;"&gt;in &lt;/span&gt;strWord)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; nIdx = strCompairTo.IndexOf(c);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;if &lt;/span&gt;(nIdx &amp;gt;= 0) return true;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;return false&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static bool&lt;/span&gt; containsOnlySpecifiedSpecChars(&lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strWord, &lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strSpecialChars)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;foreach &lt;/span&gt;(&lt;span class="Apple-style-span" style="color: blue;"&gt;char &lt;/span&gt;c &lt;span class="Apple-style-span" style="color: blue;"&gt;in &lt;/span&gt;strWord)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;if&lt;/span&gt; ((strCaps.IndexOf(c) &amp;lt; 0) &amp;amp; (strSmalls.IndexOf(c) &amp;lt; 0) &amp;amp; (strNums.IndexOf(c) &amp;lt; 0))&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; if (strSpecialChars.IndexOf(c) &amp;lt; 0)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;return&lt;/span&gt; &lt;span class="Apple-style-span" style="color: blue;"&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;return true&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static bool &lt;/span&gt;excludesSimilar(&lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strWord)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;foreach &lt;/span&gt;(&lt;span class="Apple-style-span" style="color: blue;"&gt;char &lt;/span&gt;c &lt;span class="Apple-style-span" style="color: blue;"&gt;in &lt;/span&gt;strWord)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;if &lt;/span&gt;(strWord.IndexOf(c) != strWord.LastIndexOf(c))&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;return false&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;return true&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static string&lt;/span&gt; strCaps = &lt;span class="Apple-style-span" style="color: #783f04;"&gt;"ABCDEFGHIKLMNOPQRSTUVWXYZ"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static string&lt;/span&gt; strSmalls = &lt;span class="Apple-style-span" style="color: #783f04;"&gt;"abcdefghijklmnopqrstuvwxyz"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static string&lt;/span&gt; strNums = &lt;span class="Apple-style-span" style="color: #783f04;"&gt;"0123456789"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}//class&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-3765236726178038724?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/3765236726178038724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/10/c-string-utility-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/3765236726178038724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/3765236726178038724'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/10/c-string-utility-functions.html' title='C# string utility functions containsAtLeastOneChar-containsOnlySpecifiedSpecChars-excludesSimilar'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-3N4iDxoKYm4/TrtjLaU2DjI/AAAAAAAABOY/syqbeIh8Qv4/s72-c/c-sharp-green.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-5890951288069358479</id><published>2011-09-04T23:24:00.000+05:00</published><updated>2011-11-10T10:49:32.041+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Reverse of a string by words C# example</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.blogger.com/return;" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" title="string-reversal-example"&gt;&lt;img alt="string-reversal-example" border="0" height="103" src="http://1.bp.blogspot.com/-Hqu9oB64cf4/TrtlRvNEZcI/AAAAAAAABOo/brgqxk2ziEY/s200/string-reversal-example.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Reverse of a string in C#, VB .Net, or C++ is pretty easy. Please not that we are talking about a word by word reversal, like&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Hello How Are You&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;Becomes&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;You Are How Hello&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Reversing characters inside a word is a different story.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Some people find it difficult, so I'm putting the C# example code here.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td bgcolor="#CCCCCC"&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;class&lt;/span&gt; &lt;span class="Apple-style-span" style="color: #38761d;"&gt;Program&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;public static string&lt;/span&gt; reverseIt(&lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strSource)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;string&lt;/span&gt;[] arySource = strSource.Split(&lt;span class="Apple-style-span" style="color: blue;"&gt;new char&lt;/span&gt;[] { ' ' });&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strReverse = &lt;span class="Apple-style-span" style="color: blue;"&gt;string&lt;/span&gt;.Empty;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;for&lt;/span&gt; (&lt;span class="Apple-style-span" style="color: blue;"&gt;int &lt;/span&gt;i = arySource.Length - 1; i &amp;gt;= 0; i--)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; strReverse = strReverse + " " &amp;nbsp;+ arySource[i];&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: #38761d;"&gt;Console&lt;/span&gt;.WriteLine("Original: " + strSource);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: #38761d;"&gt;Console&lt;/span&gt;.WriteLine("Reverse: " + strReverse);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;strReverse;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;static void&lt;/span&gt; Main(string[] args)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reverseIt("Hello World! Let's Reverse The String");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The algorithm is very simple and it's made easy with constructs provided by .Net framework.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Assumption:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;We assume that two words inside a given string will be separated by one white space.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;First of all we call &lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;Split&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; method on the string which user provided us, we pass in an array of characters which contains only one space, although we can put other characters like tab '\t' as separator in here. The method call&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: #cccccc;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;string&lt;/span&gt;[] arySource = strSource.Split(&lt;span class="Apple-style-span" style="color: blue;"&gt;new char&lt;/span&gt;[] { ' ' });&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;When separated, the array &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;arySource&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; will look like as given below&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Array Index&lt;/span&gt;&lt;/th&gt;&lt;th&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Word&lt;/span&gt;&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;Hello&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;World&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;2&lt;/td&gt; &lt;td&gt;Let's&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;3&lt;/td&gt; &lt;td&gt;Reverse&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;4&lt;/td&gt; &lt;td&gt;The&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;5&lt;/td&gt; &lt;td&gt;String&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Now we put a for loop, and start iterating from the end of array to beginning of array. The loop will start working from arySource.Length - 1 i.e. 5 in our case and it will keep on moving until value of variable i reaches -1.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In every iteration of loop, we pick a word a and put to the strReverse. The string will be built in a triangle form as given below&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-NGYGV7Qf2BI/TmPBF5_fcdI/AAAAAAAABIo/_-fuzs8Zsgk/s1600/reverse-string-pyramid.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="blank" title="reverse-string-pyramid"&gt;&lt;img alt="reverse-string-pyramid" border="0" src="http://3.bp.blogspot.com/-NGYGV7Qf2BI/TmPBF5_fcdI/AAAAAAAABIo/_-fuzs8Zsgk/s1600/reverse-string-pyramid.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Please feel free to comment and ask any further questions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-5890951288069358479?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/5890951288069358479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/09/reverse-of-string-by-words-c-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5890951288069358479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5890951288069358479'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/09/reverse-of-string-by-words-c-example.html' title='Reverse of a string by words C# example'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-Hqu9oB64cf4/TrtlRvNEZcI/AAAAAAAABOo/brgqxk2ziEY/s72-c/string-reversal-example.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-3588650255011596150</id><published>2011-08-04T02:23:00.000+05:00</published><updated>2011-08-04T02:23:45.146+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Code-Aerobics'/><title type='text'>Using nested conditional statements as a replacement to switch case statement in C#, C++, Java, PHP, JavaScript</title><content type='html'>Switch statements are nice, sometimes we need to just return some value based on an input variable. For example in our case I needed to get the key field of an LDAP object class we preferred to use in our software. So I had a simple C# function which went something like this&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;table bgcolor="#cccccc"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static string&lt;/span&gt; getKeyByObjectClass(&lt;span class="Apple-style-span" style="color: blue;"&gt;string &lt;/span&gt;strObjectClass){&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;switch&lt;/span&gt;(strObjectClass){&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;case&lt;/span&gt; &lt;span class="Apple-style-span" style="color: #990000;"&gt;"user"&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return&lt;/span&gt; &lt;span class="Apple-style-span" style="color: #cc0000;"&gt;"samAccountName"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;case &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"user-mailbox"&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;case &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;"user-mail"&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;case &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"contact"&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;"CN"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;case &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"contact-mail"&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"CN"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;case &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"group"&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;default&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;""&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;I thought it is possible to simplify this switch statement with a nested conditional statement. And following was the result of some deliberation ;)&lt;br /&gt;&lt;table bgcolor="#cccccc"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static string &lt;/span&gt;getKeyByObjectClass(&lt;span class="Apple-style-span" style="color: blue;"&gt;string&lt;/span&gt; strObjectClass){&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;(strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"user"&lt;/span&gt;) ? &lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt; : (strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"user-mailbox"&lt;/span&gt;) ?&lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt; :(strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"user-mail"&lt;/span&gt;) ? &lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt; : (strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"contact"&lt;/span&gt;) ? &lt;span class="Apple-style-span" style="color: #990000;"&gt;"CN"&lt;/span&gt; :(strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"contact-mail"&lt;/span&gt;) ? &lt;span class="Apple-style-span" style="color: #990000;"&gt;"CN"&lt;/span&gt; : (strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"group"&lt;/span&gt;) ? &lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt; : &lt;span class="Apple-style-span" style="color: #990000;"&gt;""&lt;/span&gt;;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;You can definitely use || operator, minimize the code, and refine the crude version of nested conditional statement we created earlier, let's just do that&lt;br /&gt;&lt;br /&gt;&lt;table bgcolor="#cccccc"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;public static string&amp;nbsp;&lt;/span&gt;getKeyByObjectClass(&lt;span class="Apple-style-span" style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;strObjectClass){&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: blue;"&gt;return&amp;nbsp;&lt;/span&gt;(strObjectClass ==&amp;nbsp;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"user" &lt;/span&gt;|| strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"user-mailbox"&lt;/span&gt; || strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"user-mail"&lt;/span&gt;) ?&amp;nbsp;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"samAccountName"&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(strObjectClass ==&amp;nbsp;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"contact" &lt;/span&gt;|| strObjectClass == &lt;span class="Apple-style-span" style="color: #990000;"&gt;"contact-mail"&amp;nbsp;&lt;/span&gt;) ?&amp;nbsp;&lt;span class="Apple-style-span" style="color: #990000;"&gt;"CN"&lt;/span&gt;&amp;nbsp;:&amp;nbsp;&lt;span class="Apple-style-span" style="color: #990000;"&gt;""&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;But now we definitely have some compromise on flexibility, maybe we'll want to use a different key for an object class say "user-mail" and then we'll have to modify this code in tiny bit different way(maintenance hell anyone?) ;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;I'm sure many intelligent folks have already done this or even a better variation but I also know that there are dumb guys and gals just like me out there who would most probably yell "Eurika!!!" on understanding the magic of nested conditional statements.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Its not just and only C# stuff, in fact the code will work with JavaScript, PHP, Java, C++ and many others with little or no variation.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-3588650255011596150?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/3588650255011596150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/08/using-nested-conditional-statements-as.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/3588650255011596150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/3588650255011596150'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/08/using-nested-conditional-statements-as.html' title='Using nested conditional statements as a replacement to switch case statement in C#, C++, Java, PHP, JavaScript'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-1983805169680243480</id><published>2011-07-30T06:09:00.000+05:00</published><updated>2011-07-30T06:09:49.939+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web'/><category scheme='http://www.blogger.com/atom/ns#' term='Joomla'/><title type='text'>Cannot rename htaccess.txt to .htaccess in cPanel File Manager</title><content type='html'>Just today I was trying to fix the 404 broken link problem with the Joomla installation on my upcoming website, http://www.ldapfilters.com which will contain certain knowledge base about LDAP and directory servers in general, along with discussion forums.&lt;br /&gt;So, they say WARNING! Apache users only! Rename htaccess.txt file to .htaccess before activating.&lt;br /&gt;I opened the File Manager from CPanel, scrolled down to the htaccess.txt file right clicked and renamed it and the File Manager finally said "No! You can't rename, a file already exists." I tried and retried several gimmicks but it didn't work.&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/span&gt; Then I decided to try legacy file explorer, I opened the CPanel Legacy File Manager, located htaccess.txt, clicked it, selected Rename from the menu, typed in .htaccess and it worked well ;)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;A Confusion:&lt;/span&gt;&lt;/b&gt;&amp;nbsp;I got confused and start thinking, shall I rename htaccess.txt to htaccess.htaccess or just remove the .txt from end of file name, and put a dot at the start of file name? Well the answer is yes, I had to take the second option. Therefore, just rename it to .htaccess that means a file with no name but just an extension.&lt;br /&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;b&gt;And one more thing&lt;/b&gt;&lt;/span&gt;, I renamed htaccess.txt to htaccess_.txt and then tried to access my website, even the home page of my Joomla based website didn't show up let alone the broken links which I was trying to fix :p&lt;br /&gt;Therefore, be very careful when you touch these configuration files, they are absolutely sensitive. Some times you catch the bug right after saving that file and refreshing that page but at some other time the setting you've just changed has got a much deeper effect which gets unleashed by some twisted user action sequence, so here's the GOLDEN ADVICE&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: orange; font-size: large;"&gt;Back those files up!!!&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-1983805169680243480?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/1983805169680243480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/07/cannot-rename-htaccesstxt-to-htaccess.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1983805169680243480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1983805169680243480'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/07/cannot-rename-htaccesstxt-to-htaccess.html' title='Cannot rename htaccess.txt to .htaccess in cPanel File Manager'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-3155588585493729164</id><published>2011-03-07T21:39:00.001+05:00</published><updated>2011-03-07T21:40:34.229+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DirectoryServices'/><category scheme='http://www.blogger.com/atom/ns#' term='.Net'/><title type='text'>System.DirectoryServices A referral was returned from the server Exception</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;System.DirectoryServices showed " &lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;b&gt;A referral was returned from the server&lt;/b&gt;&lt;/span&gt; " Exception just today, and it left me wondering what's wrong?&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I was trying to pull data from a Microsoft Active Directory Group, and while attempting to query the data following exception was occurring. An eagle eye debugging showed the cause and it was simple but stupid.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You know following is the format of LDAP connection string&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;LDAP://abc.xyz.pqr.lab:389/CN=TheGroup,CN=Users,DC=abc,DC=xyz,DC=pqr,DC=lab&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;But our dear programmer had done it a little differently, I think it was just a type, the wrong format of LDAP connection string was following&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;LDAP://abc.xyz.pqr.lab/CN=TheGroup,CN=Users,DC=abc,DC=xyz,DC=pqr,DC=lab:389&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;And this was causing the system to show the Active Directory related exception in C# .Net on Visual Studio 2008.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-3155588585493729164?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/3155588585493729164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/03/systemdirectoryservices-referral-was_07.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/3155588585493729164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/3155588585493729164'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/03/systemdirectoryservices-referral-was_07.html' title='System.DirectoryServices A referral was returned from the server Exception'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-1135395366778205572</id><published>2011-02-18T04:30:00.000+05:00</published><updated>2011-11-10T10:40:18.480+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><category scheme='http://www.blogger.com/atom/ns#' term='Automated Testing'/><title type='text'>Using Excel 2003 File As Data Source Of Visual Studio .Net Data Driven Unit or Functional Test</title><content type='html'>&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;First of all this will be the attribute tag for setting up data access of a data driven Unit or Function test in Visual Studio, I am using Visual Studio 2008 but I think same will work in Visual Studio 2010&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\FunctionalTestsDataFiles\\Smoke_Cred.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";", "ldapdest$", DataAccessMethod.Sequential), TestMethod]&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-8lBX2qsj4ao/Trtjt1Ccb7I/AAAAAAAABOg/QcJPI_ajN_I/s1600/visual-studio-2010.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-8lBX2qsj4ao/Trtjt1Ccb7I/AAAAAAAABOg/QcJPI_ajN_I/s1600/visual-studio-2010.png" /&gt;&lt;/a&gt;&lt;/div&gt;Put the name of your .xls file in place of "Smoke_Cred.xls" and put the name of your excel sheet in place of "ldapdest$", &lt;b&gt;don't forget to put the $ sign after the name of your Excel sheet.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;Be very careful with the&lt;b&gt; &lt;span style="color: red;"&gt;"System.Data.OleDb"&lt;/span&gt;&lt;/b&gt; because the people at Microsoft have made a case sensitive comparison in their code which wasted so many of my hours, and gave me too much tension.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;If you write &lt;b&gt;&lt;span style="color: red;"&gt;"System.Data.OleDB"&lt;/span&gt;&lt;/b&gt; instead, it will fail in functional/unit test but it will work fine in other connection string testing utilities.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;Second thing, the syntax of spread sheets inside excel files is different from syntax used for Access databases. You need to put a &lt;b&gt;&lt;span style="color: red;"&gt;$ &lt;/span&gt;&lt;/b&gt;character after the name of the sheet you are trying to access.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;I found an article on MSDN about running data driven test cases with Ms Access, but there was no mention of these little pieces of shit which I am sure must have been killing time of many poor developers.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;Instead of solving problems, you have to run after crappy case sensitive and idiotic connection strings, what an irony!!!&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;If you use "System.Data.OleDB" mistakenly, following error will be displayed&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;Error details:&lt;/b&gt; Unable to find the requested .Net Framework Data Provider.&amp;nbsp; It may not be installed.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;And if you somehow luckily fix this, and don't know that you need to put a $ sign after the name of that God damn excel sheet, you'll get following error&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;Error details&lt;/b&gt;: The Microsoft Jet database engine could not find the object 'ldapdest'.&amp;nbsp; Make sure the object exists and that you spell its name and the path name correctly.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;One more twist, the &lt;span style="color: red;"&gt;TestContext &lt;/span&gt;used by some s of b in MSDN article is not found anywhere by default, and you need to define it before using it. I wonder what Microsoft's trying to do with us developers.&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&amp;nbsp;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;private TestContext testContextInstance;&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;public TestContext TestContext&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;get { return testContextInstance; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;set { testContextInstance = value; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;The link of the piece of crap MSDN article is following:&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;http://msdn.microsoft.com/en-us/library/ms182527.aspx&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;I know I'm using rash and bad language but what else do you expect from someone on 4:30 AM? When you come to know that only problem with your code was that you used "B" instead of "b" and you must be intelligent enough to put a $ in the end of table name of excel sheets here. I mean why in the world Microsoft idiots cant just fix these tiny issues??? I'm too much pissed right now... literally pissed...&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-1135395366778205572?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/1135395366778205572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/02/using-excel-2003-file-as-data-source-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1135395366778205572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1135395366778205572'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/02/using-excel-2003-file-as-data-source-of.html' title='Using Excel 2003 File As Data Source Of Visual Studio .Net Data Driven Unit or Functional Test'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-8lBX2qsj4ao/Trtjt1Ccb7I/AAAAAAAABOg/QcJPI_ajN_I/s72-c/visual-studio-2010.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-7246079994461843532</id><published>2011-01-22T12:56:00.000+05:00</published><updated>2011-03-01T17:39:52.529+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Software Utilities'/><title type='text'>Turn On or  Off A Windows Computer's Display With SendMessage User32.dll Win32API Call In C++ or C#</title><content type='html'>&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span" style="color: red; font-size: x-large;"&gt;How Can I Turn Off My Laptop's Display Whenever I Want?&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;b&gt;Update:&lt;/b&gt;&lt;/span&gt; I have moved the .exe download from 4Shared to my own domain (http://www.ldapfilters.com), therefore the download is a one step process now.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I recently felt the need to turn off my laptop's monitor on my will, but you know there ain't such a button on almost all laptops. &lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;(&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d;"&gt;Not interested in tech stuff? scroll down directly to Download, and get the executeable&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;)&lt;/span&gt;&lt;/b&gt; So I tried to search around the internet for some utility, sadly speaking I didn't find any such thing. But you know I'm a programmer after all, therefore instead of searching a trust-worthy utility, I sought a do it yourself code example. I found the example here on code project:&lt;/span&gt;&lt;a href="http://www.codeproject.com/KB/system/display_states.aspx"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;http://www.codeproject.com/KB/system/display_states.aspx&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The code needed to turn your monitor off/on is literally a one liner. All you need is one line, and your monitor will be powered off as soon as you run the .exe file. Here's the code friends:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #783f04; font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;Windows.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #783f04; font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;int &lt;/span&gt;main(&lt;span class="Apple-style-span" style="color: blue;"&gt;int&lt;/span&gt; argc, &lt;span class="Apple-style-span" style="color: blue;"&gt;char&lt;/span&gt;* argv[])&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (LPARAM) 2);&lt;span class="Apple-style-span" style="color: #6aa84f;"&gt;// this c++ code will turn the monitor off&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;return &lt;/span&gt;0;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You will be wondering, &lt;span class="Apple-style-span" style="color: red;"&gt;how the monitor/display will be turned back on&lt;/span&gt;? The good news is Windows handles that part automatically. Whenever we turn off display with this cut throat application of ours, moving mouse or pressing a key will bring the monitor back to life. Although broadcasting another message will fire the display up, but we don't need that I think. Still, here's the code:&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) &lt;span class="Apple-style-span" style="color: orange;"&gt;1&lt;/span&gt;);&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Take this piece of code to &lt;span class="Apple-style-span" style="color: red;"&gt;&lt;b&gt;any C++ IDE&lt;/b&gt;&lt;/span&gt; of your choice(of course Windows duffer!!!), just compile build and your very own application to turn off the monitor will be ready.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Place the executable anywhere you want, create a shortcut on desktop, whenever you'll click it the monitor will go dark.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;And if you don't wanna do that, just download the ready to run executable of this cut throat advanced bleeding edge top class wonderful awesome @#%$#%&amp;amp;~!^&amp;amp;%$#@+ app that can shut down your PC or Laptop's display/monitor whenever you want here !!!&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: Arial, Helvetica, sans-serif; font-size: x-large;"&gt;&lt;a href="http://www.4shared.com/file/f6X4rpnT/Turn_Off_Display_Monitor.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank" title="Turn_Off_Display_Monitor"&gt;Download&lt;/a&gt;&lt;/span&gt;&lt;a href="http://www.4shared.com/file/f6X4rpnT/Turn_Off_Display_Monitor.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank" title="Turn_Off_Display_Monitor"&gt;&lt;img alt="dowload_Turn_Off_Display_Monitor" border="0" src="http://3.bp.blogspot.com/_kA2dloVQOBA/TTl56nrR5iI/AAAAAAAAAyk/0RctVtxIx-8/s1600/dowload_Turn_Off_Display_Monitor.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif; font-size: large;"&gt;Instructions:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Just place the .exe file anywhere in your system, double clicking it will turn off the monitor you may create a shortcut on desktop, or pin it to task bar for easy access (details below).&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Moving the mouse, or pressing a key on keyboard will turn your system's display back on.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span class="Apple-style-span" style="color: red; font-family: Verdana, sans-serif;"&gt;Please keep that in mind:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This utility does not open any network communications port&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This utility does not read/write any kind of files to/from your computer's hard disk&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This utility does not read/write anything to/from Windows Registry.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Therefore, if the file you download tries to do any of the above, the file is not original and someone has tampered with it.&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: large;"&gt;Making Things Even Better (Value Addition):&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;There's a very cool Windows 7 feature which I've used to make things even better on my laptop.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The feature goes like you can access the shortcuts pinned to Windows by pressing Windows Button + a number. The leftmost minimized program or pinned shortcut will be activated by pressing Windows + 1, second left with Windows + 2, so on and so forth. For example see the snap shot of my current Windows Toolbar&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_kA2dloVQOBA/TTmeceONDmI/AAAAAAAAAyw/P1WgzsIFRHM/s1600/desktop_snapshot_Turn_Off_Display_Monitor.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="94" src="http://3.bp.blogspot.com/_kA2dloVQOBA/TTmeceONDmI/AAAAAAAAAyw/P1WgzsIFRHM/s640/desktop_snapshot_Turn_Off_Display_Monitor.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The yellow numbers aren't found originally in the interface, I've annotated the snap shot on purpose. Right now, if I will press Windows Key and then press 2 key(not from num-pad) the Windows Media player which is second from left will be maximized. Similarly, Windows 5 will cause Google Chrome to open up. Windows 8 will maximize Ms Paint. I have pinned the .exe file of our cut throat power off display application to Task bar. Therefore, if I will press Windows key + 1 display of my laptop will be turned off.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif; font-size: large;"&gt;Technical Explanation:&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;b&gt;How Windows Works&lt;/b&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Basically we need to understand the architecture of Windows applications to get the core of what's happening in this single line of code.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In a Windows environment, we don't interact with any application directly. Instead whenever we perform an action we are talking to Windows Operating System, the OS takes our command/action and passes it over to an application depending on the location of the action/command/event.&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;b&gt;For Example:&lt;/b&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Like if you click in a Ms Word window, following will happen:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Windows OS will catch the message&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It will see that currently the window associated with Ms Word was active&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It will pass over your command in form of a message to Ms Word&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Each and every Windows based application contains a "Windows Message Message Pump" loop, which keeps watching for incoming messages from Windows OS&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In this case, the message pump inside Ms Word will catch the message that "user clicked somewhere".&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Then Ms Word will handle the message what ever way it wants to.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If an application has not handled a certain message, the message will simply have no affect on its health and the application will just discard the message.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;People writing code for .Net platform (usually) don't know these things, but that's the basic Ms Windows architecture, and its not going anywhere any time soon. The "Windows Message Pump" plus WndProc method is alway in there.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Where does SendMessage() fit in?&lt;/b&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;SendMessage is found in User32.dll, and its a Win32 API call(scary bare bone stuff for .Netters).&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In this program we are broadcasting a message, which is not intended for any specific application. Like the fishermen broadcast help requests on radio. We are just saying &lt;span class="Apple-style-span" style="color: blue;"&gt;"Hey anybody out there, I am sending &amp;nbsp;a WM_SYSCOMMAND which is related to SC_MONITORPOWER with a value of 2"&lt;/span&gt;. &lt;span class="Apple-style-span" style="color: red;"&gt;Luckily &lt;/span&gt;there is a portion of Windows which is handling this message, its the same part which turns your display off after a certain amount of time.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This function call won't affect anything else on your system, cause no other application is consuming this message.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;So, in the end, your display is powered off so that you can sit back and relax ;)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You might have noticed that I just provided C++ source code, and there ain't not C# .Net code as sample. I think its quite easy to setup p/Invoke calls these days, I am intentionally avoiding the topic as I want to keep the article short and to the point. Just if you've understood the scheme of things, you can easily setup a C#.Net or VB.Net version.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red; font-family: Verdana, sans-serif;"&gt;DISCLAIMER: There is no guarantee or warantee that this program will work as specified in this post. Author will not be responsible for any damage due to use of instructions provided in this post.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-7246079994461843532?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/7246079994461843532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2011/01/turn-on-or-off-windows-computers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/7246079994461843532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/7246079994461843532'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2011/01/turn-on-or-off-windows-computers.html' title='Turn On or  Off A Windows Computer&apos;s Display With SendMessage User32.dll Win32API Call In C++ or C#'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_kA2dloVQOBA/TTl56nrR5iI/AAAAAAAAAyk/0RctVtxIx-8/s72-c/dowload_Turn_Off_Display_Monitor.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-6804734760768880349</id><published>2010-09-26T15:55:00.000+05:00</published><updated>2010-09-26T15:55:49.222+05:00</updated><title type='text'>sizeof operator on a double array in c++</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Arial; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&lt;script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/3823952.js"&gt;&lt;/script&gt;&lt;noscript&gt; &lt;a href="http://polldaddy.com/poll/3823952/"&gt;char[50][5] Ary; cout&lt;/a&gt;&lt;span style="font-size:9px;"&gt;&lt;a href="http://polldaddy.com/features-surveys/"&gt;online survey&lt;/a&gt;&lt;/span&gt;&lt;/noscript&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-6804734760768880349?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/6804734760768880349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2010/09/sizeof-operator-on-double-array-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6804734760768880349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6804734760768880349'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2010/09/sizeof-operator-on-double-array-in-c.html' title='sizeof operator on a double array in c++'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-7653282723212086655</id><published>2010-09-25T22:18:00.000+05:00</published><updated>2010-09-25T22:39:03.193+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Char**'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Char** Array of Strings in C and C Plus Plus(C++)</title><content type='html'>&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;Defining strings in C and C++:&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;Basically, a string is an array of characters (char) data type variables. And it is defined as following:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;char myString[50];&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: black; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;It is possible to initialize the array of characters at run time&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;char myInitializedString[50]={"I am invincible..."};&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;&lt;span class="Apple-style-span" style="color: black;"&gt;An alternate technique of defining character arrays with the help of char pointers can be used as well, which is demonstrated below:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;char* myInitializedCharPtr = "Here we go again";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;b&gt;Multi dimensional arrays in c and c++:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;What if someone wants to store multiple strings... in an array... array of strings in other words... well... its fairly simple to create an initialized array of strings&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: blue; font-family: 'Courier New',Courier,monospace;"&gt;char ArrayOfStringsInitialized[3][50] = {"Rock and Rolla","iToka","Thats it"};&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;This array of strings contains 3 strings, each of length upto 50 characters. &lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;To iterate the array we just created, do the following... &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: small;"&gt; &lt;span style="font-family: 'Courier New',Courier,monospace;"&gt;for(int n = 0; n&amp;lt;=2&lt;span style="color: #38761d;"&gt;/*less than last element of array*/&lt;/span&gt;;n++)&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;br style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New',Courier,monospace; font-size: small;"&gt;{&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;br style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New',Courier,monospace; font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;ArrayOfStringsInitialized[n]&amp;lt;&amp;lt;endl;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;br style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: 'Courier New',Courier,monospace; font-size: small;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;For two dimensional array defined with this technique, the programmers don't need to free the memory explicitly.&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;Dynamic two dimensional arrays&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;Suppose we need to create a multi-dimensional array on run time, using pointers... We will need a char double pointer or char**, and it will make the code look something like this&lt;/span&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;char** greenLandMD;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: small;"&gt;greenLandMD = new char*[5];&lt;span style="color: lime;"&gt;// &lt;/span&gt;&lt;span style="color: #274e13;"&gt;&lt;span style="color: lime;"&gt;initialize the &lt;b&gt;double pointer&lt;/b&gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;greenLandMD[0]=new char[4];&lt;span style="color: lime;"&gt;// &lt;/span&gt;&lt;span style="color: #274e13;"&gt;&lt;span style="color: lime;"&gt;initialize &lt;b&gt;1st char*&lt;/b&gt;, with &lt;/span&gt;&lt;span class="Apple-style-span" style="color: lime;"&gt;capacity of 4 chars&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;greenLandMD[1]=new char[5];&lt;/span&gt;&lt;span style="color: #274e13; font-size: small;"&gt;&lt;span style="color: lime;"&gt;// initialize &lt;b&gt;2nd &lt;/b&gt;char*, with &lt;/span&gt;&lt;span class="Apple-style-span" style="color: lime;"&gt;capacity of 5 chars&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;strcpy(greenLandMD[0],"Bst @");&lt;span class="Apple-style-span" style="color: lime;"&gt;//copy some data to 1st string&lt;/span&gt;&lt;br /&gt;strcpy(greenLandMD[1],"Bi! 1");&lt;span class="Apple-style-span" style="color: lime;"&gt;//copy some data to 2nd string&lt;/span&gt;&lt;br /&gt;greenLandMD[3]="W ared";&lt;span class="Apple-style-span" style="color: lime;"&gt;// an alternate way of copying data&lt;/span&gt;&lt;br style="color: lime;" /&gt;&lt;span style="color: #274e13;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: lime;"&gt; // print and see the data&lt;/span&gt;&lt;br /&gt;cout&amp;lt;&amp;lt;greenLandMD[0]&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;greenLandMD[1]&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;greenLandMD[3]&amp;lt;&amp;lt;endl;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;Console will show&lt;/span&gt;&lt;/div&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="background-color: black; color: white; font-family: courier;" width="300"&gt;c:\&amp;gt;Bst @&lt;br /&gt;Bi! 1&lt;br /&gt;W ared&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;An alternate way to achieve the same result is given below&lt;/span&gt;&lt;br /&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span class="Apple-style-span"&gt;cout&amp;lt;&amp;lt;*(greenLandMD+0)&amp;lt;&amp;lt;endl;&lt;br /&gt;cout&amp;lt;&amp;lt;*(greenLandMD+1)&amp;lt;&amp;lt;endl;&lt;br /&gt;cout&amp;lt;&amp;lt;*(greenLandMD+3)&amp;lt;&amp;lt;endl;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;At this point, the array will look something like this&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://picasaweb.google.com/lh/photo/hseEQcmAeqhDq6pf6LbJpBjtbcm3uFXN85t-cyxrHek?feat=embedwebsite" style="margin-left: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img height="86" src="http://lh3.ggpht.com/_kA2dloVQOBA/TJyfIi2EbfI/AAAAAAAAAn0/Eb8B1OCLQ_U/s400/Multidimensional_Array.png" width="400" /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;There are two things to notice in this image&lt;br /&gt;1- The size of strings contained by array of strings varies.&lt;br /&gt;2- It is possible to leave un-initialized&amp;nbsp;space at any slot of a multi dimensional array in c/c++.&lt;br /&gt;It is a programmer's responsibility to free the memory acquired using this technique, missing such things create memory leaks which cause performance decrease, security related problems, and an all out crash some times.&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;Freeing memory of char * and char**&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;Deleting the main array will suffice to free the memory consumed by double pointers. In our case, we'll do following:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: Arial,Helvetica,sans-serif; font-size: small;"&gt;delete [] greenLandMD;&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif; font-size: small;"&gt;I think this much is enough on this topic, for more please feel free to comment this post.&lt;/span&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-7653282723212086655?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/7653282723212086655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2010/09/char-array-of-strings-in-c-and-c-plus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/7653282723212086655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/7653282723212086655'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2010/09/char-array-of-strings-in-c-and-c-plus.html' title='Char** Array of Strings in C and C Plus Plus(C++)'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_kA2dloVQOBA/TJyfIi2EbfI/AAAAAAAAAn0/Eb8B1OCLQ_U/s72-c/Multidimensional_Array.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-6772819911452241934</id><published>2010-01-15T14:35:00.000+05:00</published><updated>2011-04-05T13:26:29.593+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft Certification'/><category scheme='http://www.blogger.com/atom/ns#' term='MCTS'/><category scheme='http://www.blogger.com/atom/ns#' term='MCPD'/><title type='text'>Path to Microsoft Certification for programmers</title><content type='html'>&lt;a title="Path-To-Microsoft-Certification-MCTS"  href="http://3.bp.blogspot.com/_kA2dloVQOBA/S1A3cvPyrkI/AAAAAAAAAmQ/cBw4BIqZlO8/s1600-h/Microsoft_Cert.JPG" target="_blank"&gt;&lt;img alt="Path-To-Microsoft-Certification-MCTS" border="0" id="BLOGGER_PHOTO_ID_5426898517840014914" src="http://3.bp.blogspot.com/_kA2dloVQOBA/S1A3cvPyrkI/AAAAAAAAAmQ/cBw4BIqZlO8/s400/Microsoft_Cert.JPG" style="display: block; height: 166px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;In university days I once tried to follow path to Sun Java Certified Programmer. On their web site I found very nice flow charts. For Microsoft's certification I could not find anything of this sort therefore I decided to collect data from Microsoft's web and create my own Microsoft Certification Tree diagram.&lt;br /&gt;Everything seems to be starting from Exam 70-536: TS: Microsoft .Net Framework, Application Development Foundation. We will get MCTS after passing two exams, and MCPD after passing third exam of next stage.&lt;/div&gt;&lt;span style="Color:Red"&gt;&lt;strong&gt;Update: &lt;/strong&gt;&lt;/span&gt; Everything still starts from Exam 70-536.&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-6772819911452241934?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/6772819911452241934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2010/01/path-to-microsoft-certification-for.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6772819911452241934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6772819911452241934'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2010/01/path-to-microsoft-certification-for.html' title='Path to Microsoft Certification for programmers'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_kA2dloVQOBA/S1A3cvPyrkI/AAAAAAAAAmQ/cBw4BIqZlO8/s72-c/Microsoft_Cert.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-2548194071820699950</id><published>2009-06-09T15:02:00.000+06:00</published><updated>2011-07-30T07:58:08.280+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>std::ostringstream AKA String Streams...</title><content type='html'>Want to share a few bits about a very important and useful feature of standard library today. std::ostringstream can come in handy in many situation. You know we often need to concatenate strings. And often it becomes tedious, usually this is done using strcat funtion in C and + operator in C++ &amp;nbsp;std::string class . For example&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;// C style&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;char * szFullName = strcat("First Name ", " Last Name");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;//C++ style&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;std::string strFirstName = "First Name";&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;std::string strLastName = "Last Name";&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;std::string strFullName = strFirstName + " " + strLastName;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;std::ostringstream gives us a convenient way to build strings conveniently.&lt;br /&gt;std::ostringstream provides functionality very much similar to sprintf function of C language.&lt;br /&gt;&lt;br /&gt;Like for example you got names, ages, and heights of a few kids stored in arrays and you want them to be printed nicely on screen. Perhaps you could use a std::string and + operator to join string but I think using ostringstream will be a better approach.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;const int CONST_ARRAY_SIZE = 3;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;std::string aryStrNames[CONST_ARRAY_SIZE] = {"Ali", "Jason", "Shiv"};&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;int aryNAges[CONST_ARRAY_SIZE] = {5,9,11};&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;float aryFHeight[CONST_ARRAY_SIZE]={3.2,4.0,4.4};&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;std::ostringstream outBuffer;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;for(int i = 0; i &amp;lt; CONST_ARRAY_SIZE; i++){&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;outBuffer&amp;lt;&amp;lt;aryStrNames[i]&amp;lt;" is " &amp;lt;&amp;lt; aryNAges[i] &amp;lt;&amp;lt; " years old, and his height is "&amp;lt;&amp;lt; aryFHeight[i] &amp;lt;&amp;lt; endl;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;}// end for i&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue; font-family: 'Courier New', Courier, monospace;"&gt;cout&amp;lt;&amp;lt; outBuffer.str();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here's a link to ostringstream on C Plus Plus&lt;br /&gt;&lt;a href="http://www.cplusplus.com/reference/iostream/ostringstream/"&gt;http://www.cplusplus.com/reference/iostream/ostringstream/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-2548194071820699950?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/2548194071820699950/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/06/stdostringstream-aka-string-streams.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/2548194071820699950'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/2548194071820699950'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/06/stdostringstream-aka-string-streams.html' title='std::ostringstream AKA String Streams...'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-4795513925079556216</id><published>2009-03-17T21:53:00.001+05:00</published><updated>2009-06-26T19:42:16.107+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='std::string'/><category scheme='http://www.blogger.com/atom/ns#' term='substring'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Working with std::string::substring() method</title><content type='html'>&lt;span style="font-family:arial;"&gt;Though it is a very simple function, but sometimes people(me too) make a mistake when coding thing up. For example we have a std::string strHello&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_kA2dloVQOBA/SfmDKRnZrWI/AAAAAAAAACo/KQm4BSZLw4U/s1600-h/Hello_World.GIF"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 23px;" src="http://2.bp.blogspot.com/_kA2dloVQOBA/SfmDKRnZrWI/AAAAAAAAACo/KQm4BSZLw4U/s320/Hello_World.GIF" alt="" id="BLOGGER_PHOTO_ID_5330435846520286562" border="0" /&gt;&lt;/a&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;int nPositoinOfSemiColon = strHello.find(";", 0);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;find &lt;/span&gt;&lt;span style="font-family:arial;"&gt;method will find the fist parameter ";" in strHello, starting from second parameter i.e. 0.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now the&lt;/span&gt; &lt;span style="color: rgb(51, 51, 255);font-family:courier new;"&gt;nPositoinOfSemiColon &lt;/span&gt;&lt;span style="font-family:arial;"&gt;will contain either string::npos which means the string provided to find method was not found in strHello. Or in our case, 5 which is the location of ";".&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;strHello.substr(0, &lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositoinOfSemiColon &lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;will return "Hello", i.e. 5 characters starting from location 0 in strHello.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now consider&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;int nPositionOfSecondSemiColon = strHello.find(";", nPositionOfSemiColon);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Well... writing following line of code will... wonder what...&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;strHello.substr(&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositionOfSemiColon&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;, &lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositionOfSecondSemiColon&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;CAUSE AN ERROR!!! FOLKS!!! ERR GRR ERROOORRR... a vicious cruel ugly error... heh heh heh...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Poor baby programmers will asK "But why Uncle why???"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Because, of the values in variables at this time are...&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositionOfSemiColon = 5&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-family:lucida grande;"&gt;AND&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositionOfSecondSemiColon&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt; = 11&lt;/span&gt;&lt;br /&gt;That means&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;strHello.substr(5&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;, 11&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;i.e. extract 11 characters starting from location 5 in strHello.&lt;br /&gt;Whereas, 11 is total length of strHello...&lt;br /&gt;&lt;br /&gt;The right way to go is&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;strHello.substr(&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositionOfSemiColon&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;,&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;     nPositionOfSecondSemiColon&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt; - &lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;nPositionOfSemiColon&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That means&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;strHello.substr(5&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;, 6&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;"&gt;);&lt;/span&gt; //  That means ";WORLD"&lt;br /&gt;&lt;br /&gt;Cheers folks... have fun... remember... coding is a noble pursuit... so just keep hitting it hard... savor the wonders and joys of turning real world into programming language codes, and bear the tensions with enough tolerance...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-4795513925079556216?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/4795513925079556216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/working-with-stdstringsubstring-method.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/4795513925079556216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/4795513925079556216'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/working-with-stdstringsubstring-method.html' title='Working with std::string::substring() method'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_kA2dloVQOBA/SfmDKRnZrWI/AAAAAAAAACo/KQm4BSZLw4U/s72-c/Hello_World.GIF' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-4884438211620881881</id><published>2009-03-17T21:50:00.001+05:00</published><updated>2009-06-26T19:41:01.268+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++ interview questions'/><title type='text'>More C/C++ Interview Questions</title><content type='html'>I was keeping this post on hold for almost a month, so that I will post the questions along with the answers... but due to some reasons, I was unable to post the answers...&lt;br /&gt;Will do it some time later in future...&lt;br /&gt;For the time being, the C/C++ interview questions are given below...&lt;br /&gt;If anybody finds out an answer, feel free to write it in comments...&lt;br /&gt;&lt;br /&gt;1. What is the difference between a pointer and array?&lt;br /&gt;2. Is it possible to find out the size of an array?&lt;br /&gt;3. What is NULL?&lt;br /&gt;4. How can we find if a pointer contains a valid value or not?&lt;br /&gt;5. We have a circular linked list, and its tail -&gt; next is not pointing to List -&gt; Head. How can we diagnose such an error condition?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-4884438211620881881?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/4884438211620881881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/more-cc-interview-questions.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/4884438211620881881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/4884438211620881881'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/more-cc-interview-questions.html' title='More C/C++ Interview Questions'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-1527106722550844204</id><published>2009-03-09T23:02:00.000+05:00</published><updated>2009-04-30T16:16:29.297+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='std::string'/><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='printrf'/><title type='text'>A tricky error, when using std::string with *printf funtions</title><content type='html'>&lt;span style="font-family:arial;"&gt;All of us know what this code &lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;(listing 1)&lt;/span&gt;will do...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;&lt;br /&gt;char * szName = "Ex";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;printf("%s", szName );&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;Will anybody tell what will be the result of these lines&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;(listing 2)&lt;/span&gt;...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;std::string strName = "Zed";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;printf("%s", strName);&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;Ladies and gentlemen...&lt;span style="color: rgb(204, 0, 0);font-family:arial;" &gt; &lt;b&gt;listing two will cause your program to crash&lt;/b&gt;&lt;/span&gt;. This is a very common mistake made by programming newbies... though an experienced pro may also do the same...&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:arial;"&gt;The right way to print the string is&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;&lt;br /&gt;std::string strName = "Zed";&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;printf("%s", strName.c_str());&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;such errors are very difficult to spot...&lt;/span&gt; Because when reading the code, one often unconsciously considers these lines are correct...&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;Now people will ask that why in the world will someone create such a ridiculous blend of C and C++... The answer is... I don't know why... But anybody is absolutely free to mix the two compatible languages into a cocktail... I myself did this... when I was new into the dark realm of C/C++ programming... I had my own reasons... others will have their own...&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-weight: bold;"&gt;note&lt;/span&gt;: *printf means any of the following funtion calls {printf, sprintf, fprintf}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-1527106722550844204?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/1527106722550844204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/tricky-error-when-using-stdstring-with.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1527106722550844204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1527106722550844204'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/tricky-error-when-using-stdstring-with.html' title='A tricky error, when using std::string with *printf funtions'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-5112717055010588380</id><published>2009-03-04T23:25:00.000+05:00</published><updated>2009-06-26T19:43:29.583+06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='Modern Computing'/><title type='text'>Relevance of C/C++ in today's computing</title><content type='html'>&lt;span style="font-family:arial;"&gt;A question mostly asked by fresh graduates is &lt;span style="color: rgb(51, 102, 255);"&gt;"C/C++ are still being used"&lt;/span&gt;? The answer is &lt;span style="color: rgb(51, 102, 255);"&gt;"Yes of course"&lt;/span&gt;, C/C++ are still being widely used. Many open source projects are done using C/C++. Modern computing scene would be very different if C/C++ were not there... For example&lt;/span&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;1. Asterisk the open source PBX is written using plain old C language.&lt;/span&gt;&lt;br /&gt;2. &lt;span style="font-family:arial;"&gt;Maya, a top notch 3D animation suite is written using C++.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;3. Postgres, leading open source DBMS which competes to Oracle is done using C.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;C is considered the language of choice for writing Operating Systems. All Linux based operating systems are written using C. Microsoft Windows is written using C/C++. They (folks @ Redmond) tried to write Windows Vista using C#, but failed miserably.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;C is known as "Mother of all programming languages". &lt;/span&gt;&lt;span style="font-family:arial;"&gt;C/C++ are primarily used to write mission critical software, when we need high speed and smaller memory foot prints.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;I agree that we are living in an internet age, languages lis PHP/ASP.Net/Ruby on Rails are everywhere these days. But does anybody think, what is the engine powering these languages? The web-server which executes PHP code, the browser which displays CSS/HTML and dances around with AJAX, Adobe's Flash things, and many more are all done using C/C++.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Sometimes I think, I will do a detailed workshop titled "The Real Power of C/C++". I'm pretty ambitious in this regards, and I'll surely tell the world about "the happening"...&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-5112717055010588380?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/5112717055010588380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/relevance-of-cc-in-todays-computing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5112717055010588380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5112717055010588380'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/03/relevance-of-cc-in-todays-computing.html' title='Relevance of C/C++ in today&apos;s computing'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-5771456277965923510</id><published>2009-02-19T12:33:00.000+05:00</published><updated>2010-09-21T17:28:24.162+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web method'/><category scheme='http://www.blogger.com/atom/ns#' term='hyperlink'/><category scheme='http://www.blogger.com/atom/ns#' term='web-method'/><category scheme='http://www.blogger.com/atom/ns#' term='web service'/><category scheme='http://www.blogger.com/atom/ns#' term='web-service'/><title type='text'>Calling a web-method from a hyperlink</title><content type='html'>&lt;span style="font-family: arial;"&gt;I've observed this trend in tech-industry, we will find many articles on difficult topics but its very difficult to find answers to simple questions.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;I once faced such a question and figured it out after some experimenting.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The question is how to call a web method (a method exposed by a web service) from a plain HTML web page??? In other words how to call webmethods directly???&lt;/span&gt; &lt;span style="font-family: arial;"&gt;Well, folks its really simple to call a web-method from a hyperlink... The HTML goes like this...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;&amp;lt;a&lt;span style="color: #3366ff; font-family: courier new;"&gt; href = "http://localhost/abcGateway/xgateway.asmx/dostartRecording?recchannel=19"&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #3366ff; font-family: courier new;"&gt;Start Recording&lt;/span&gt;&lt;br /&gt;&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Where I have a web-service whose main page is xgateway.asmx, and it exposes a web method "dostartRecording", this web-method takes a parameter "recchannel".&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&amp;nbsp;Hi ho now you can enjoy calling a web method directly from your web page.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-5771456277965923510?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/5771456277965923510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/calling-web-method-from-hyperlink.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5771456277965923510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5771456277965923510'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/calling-web-method-from-hyperlink.html' title='Calling a web-method from a hyperlink'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-1715321755069150463</id><published>2009-02-19T12:27:00.001+05:00</published><updated>2011-11-10T15:34:03.153+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='API'/><category scheme='http://www.blogger.com/atom/ns#' term='Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++ interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Software Framework'/><title type='text'>Difference between Framework and API</title><content type='html'>&lt;span style="font-family: arial;"&gt;&lt;/span&gt; &lt;span style="font-family: arial;"&gt;&lt;/span&gt; &lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: 'Times New Roman'; margin: 0px;"&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="color: #3366ff; font-family: 'courier new';"&gt;Software Framework:&lt;/span&gt;&amp;nbsp;Is a re-usable design for a software system (or subsystem). A software framework may include programs, code libraries, a scripting language, other software to help develop and glue together the different components of a software project. Various parts of the framework maybe exposed through an API.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-family: arial;"&gt;Microsoft's .Net framework is a very good example of a software framework. It contains compilers, class libraries, an IDE(Visual Studio), and a runtime. Another example is OpenCog: A Software Framework for Integrative Artificial General Intelligence.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; margin: 0px;"&gt;&lt;/div&gt;&lt;div style="font-family: 'Times New Roman'; margin: 0px;"&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="color: #3366ff; font-family: 'courier new';"&gt;API (Application Programming Interface):&lt;/span&gt;&amp;nbsp;Is a set of routines( AKA methods, functions), data structures, object classes, and/or protocols provided by libraries and/or operating system services in order to support the building of applications.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-family: arial;"&gt;An example is Microsoft TAPI(Telephony API), or MySQL connectivity API, or Google MAPS API.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_kA2dloVQOBA/TJ94uQqbuyI/AAAAAAAAAoY/usSgkpTkoLM/s1600/dot_net_framework.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img border="0" height="250" src="http://4.bp.blogspot.com/_kA2dloVQOBA/TJ94uQqbuyI/AAAAAAAAAoY/usSgkpTkoLM/s320/dot_net_framework.png" width="350" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-family: arial;"&gt;In Microsoft's .Net Framework, only the Base Class Library or BCL are the API. The framework is a bigger thing. API is a part, framework is a whole. Although, API can exist on its own, without a framework as well. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style="font-family: arial;"&gt; &lt;/span&gt; &lt;span style="font-family: arial;"&gt;A friend was telling me yesterday "I interviewed someone, he had no idea about difference between Framework and an API". I replied"Owwww that's dumb". In fact,  had no idea about the difference either... :p. Well, I think this much is enough to illustrate the difference between Software Framework and API, or Software Framework vs API. ;)&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Another example pictured below is the Google's Android Mobile Platform,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a title="android-system-architecture" href="return;" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img alt="android-system-architecture" border="0" height="229" src="http://4.bp.blogspot.com/-52AVD0B_4mU/TruhMnoJ35I/AAAAAAAABOw/x_adOIRJFVc/s320/android-system-architecture.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: arial;"&gt;You see this platform contains many things, a kernel for low level tasks, certain libraries for OS level chores, Delvik Virtual Machine (an enriched clone of Java Virtual Machine), and the "Application Framework" on on the "third story". Any software we write for Android smart phones will reside on 4th floor, which is labelled "Applications" here.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-1715321755069150463?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/1715321755069150463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/difference-between-framework-and-api.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1715321755069150463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1715321755069150463'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/difference-between-framework-and-api.html' title='Difference between Framework and API'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_kA2dloVQOBA/TJ94uQqbuyI/AAAAAAAAAoY/usSgkpTkoLM/s72-c/dot_net_framework.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-6793425112103968800</id><published>2009-02-18T19:17:00.000+05:00</published><updated>2010-09-21T17:11:37.336+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='std::map'/><category scheme='http://www.blogger.com/atom/ns#' term='std::vector'/><title type='text'>Working with a std::vector inside an std::map</title><content type='html'>Suppose we have a map which contains std::string keys and std::vector values, it will be defined as following&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;div style="background-color: white; color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;std::map&amp;lt;std::string,std::vector&amp;gt; &lt;std::string,&gt;map_str_vector;&lt;/std::string,&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I was doing something like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;std::vector&lt;std::string&gt; vec_active_channels;&lt;/std::string&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;vec_active_channels.push_back("Some string");&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;map_str_vector["Some_Key"] = vec_active_channels;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Later in the code, I was erasing an element from the vector like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;std::vector&lt;std::string&gt; vec_temp = map_str_vector["Some_Key"];&lt;/std::string&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;vec_temp.erase(0);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;But you know what, later on when I examined the vector, its size won't be changed.&lt;/div&gt;&lt;div&gt;The reason is when I did:&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;std::vector&lt;std::string&gt; vec_temp = map_str_vector["Some_Key"];&lt;/std::string&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;A new object of std::vector&lt;std::string&gt; was created and placed in vec_temp, and the call&lt;/std::string&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;vec_temp.erase(0);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;was erasing first element from the new object.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The right way to remove a std::vector from a std::map value field is given below&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #3366ff;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;map_str_vector["Some_Key"].erase(0);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;We can put an if statement behind this erase operation, to check whether this key exists in the map or not.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-6793425112103968800?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/6793425112103968800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/working-with-stdvector-inside-stdmap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6793425112103968800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6793425112103968800'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/working-with-stdvector-inside-stdmap.html' title='Working with a std::vector inside an std::map'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-1153141026631971728</id><published>2009-02-18T18:10:00.000+05:00</published><updated>2009-02-18T19:16:49.788+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='free'/><category scheme='http://www.blogger.com/atom/ns#' term='Standard Template Library'/><category scheme='http://www.blogger.com/atom/ns#' term='virtual destructor'/><category scheme='http://www.blogger.com/atom/ns#' term='STL'/><category scheme='http://www.blogger.com/atom/ns#' term='pure virtual funtion'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++ interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='friend function'/><category scheme='http://www.blogger.com/atom/ns#' term='callback funtion'/><category scheme='http://www.blogger.com/atom/ns#' term='function pointer'/><category scheme='http://www.blogger.com/atom/ns#' term='malloc'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='copy constructor'/><title type='text'>C/C++ Common interview questions</title><content type='html'>&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Hi people, I got 2 years of experience and looking for a new job these days. I thought to write down the most commonly asked technical questions, they asked me.&lt;/span&gt;&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:large;"&gt;Questions&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;What is the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;difference &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;between &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;new/delete&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt; and &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;malloc(), free()&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;What if we allocate memory using &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;new &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;and release it with &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;free()&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Why do we need &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;virtual destructors&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;C++ compiler provides a copy costructor and overloaded assignment operator by default, why do we need to write our own &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;copy constructors&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Have you ever used &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;STL&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;, why do we use STL, if yes then what containers?&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;What are &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;function pointers&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;What happens when a &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;call&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;back funtion&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt; is called?&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Differences&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt; between &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;C&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt; and &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;C++&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Write a program in C language which prints "Hello World!" on screen, &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;without using even a single semi colon ';'&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Swap&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt; two integers without using a third one.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;If we have a struct &lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;struct ABC{int n; char c;}&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;; &lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0);"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Suppose an integer takes 4 bytes. How many space in memory will be occupied by an instance of this structure?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Why do we need &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;pure virtual functions&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;?&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;What are &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;friend functions&lt;/span&gt;?&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-size:large;"&gt;Answers&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold;font-size:18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;malloc()&lt;/span&gt; &lt;/span&gt;and &lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;free()&lt;/span&gt;&lt;/span&gt; &lt;span class="Apple-style-span"  style="font-family:arial;"&gt;are C language functions used to allocate and free memory. These funtions simply allocate memory for a variable. &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;new/delete&lt;/span&gt; are C++ language operators, &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;new&lt;/span&gt; &lt;/span&gt;operator allocates memory needed by an object and then calls the constructor function of that object to perform any initializations. Applying &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span"  style="font-family:georgia;"&gt;delete &lt;/span&gt;&lt;/span&gt;to an object causes a call to the destructor function of that object, and afterwards a release of memory. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;The memory occupied by the object will be returned to Operating System, but the destructor of that object won't be called.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;Suppose you use &lt;/span&gt;&lt;small&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;delete&lt;/span&gt;&lt;/small&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt; &lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;with a base class pointer to a derived  class object to destroy the derived-class object. If the base-class destructor  is not virtual, then &lt;/span&gt;&lt;small&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;delete&lt;/span&gt;&lt;/small&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;, like a normal member function, calls  the destructor for the base class, not the destructor for the derived class.  This will cause only the base part of the object to be destroyed.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;C++ default &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;copy constructor&lt;/span&gt; and &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;assignment operator&lt;/span&gt; perform a member to member copy of the instance variables contained by an object. If we have instance variables of pointer types in an object say object1, and we perform a straight member to member copy to object2. The pointer type instance variables in both object1 and object2 will be pointing to same memory locations. And if we delete one object, the pointers in other object will become invalid without that object ever knowing. This will cause a program crash.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Standard Template Library&lt;/span&gt; is a standard peer revised and optimazed collection of containers and algorithms. Because it is standard, it is cross platform and any compiler supporting C++ standards must work with STL. Using STL cuts developement time, and increases program reliablity. I have personally  used vector, queue, and map containers.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Callback funtions &lt;/span&gt;are also known as delegates. Callbacks are used when we want a method to be called from some other thread of execution. For example the boost::regex_grep function, its parameters are a large(or maybe small) string, a regular expression, and a call back funtion. The string can be very very long and finding the matches may take too much time, so whenever this boost::regex_grep funtion finds a match satisfying the supplied regular expression it will call the funtion in our code specified in callback argument.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;A callback funtion is basically a pointer to the starting location of some code, AKA funtion pointer. When a callback funciton is called, its parameters are pushed to stack. Then the control is transferred to the funtion pointer location and then the control resumes from the function pointer location.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;C is a functions based language, and it does not provide anything to group data with funtions which will manipulate that data. C++ is an Object Oriented language, and it provides rich constructs to group data with funtions which will manipulate it (AKA&lt;span class="Apple-style-span" style="font-weight: bold;"&gt; Data Encapsulation&lt;/span&gt;). It is possible to implement solutions close to real world using C++, by implementing heirarchical designs. C++ saves developement time by code resue through &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Inheritance &lt;/span&gt;as well.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 102, 255);"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;void main(void){if(printf("Hello World!")){}}&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 102, 255);"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;int a = 10; int b = 20; a = a+b; b = a - b; a = a - b;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;An instance of this struct will take 8 bytes, because the C++ language compiler performs memory padding at every 4 bytes.It means, that a variable occupies at least 4 bytes in memory. 4 bytes is the basic unit of allocation in memory. This struct will take 4 + 1 = 5 bytes in memory, but the compiler will scale it up to 8 bytes by memory padding.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;If a class includes a &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;pure virtual function&lt;/span&gt;, it can't be instantiated. A class which contains a pure virtual function is an abstract class. Abstract classes are also known as interfaces. In situations where we are defining interfaces, which will be used to contain pointers to child class objects only there must be some way to stop people from creating objects of these interfaces. Pure virtual functions server the purpose. Because an it compiler will stop us from creating an object of an Abstract class.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="Apple-style-span"  style="font-family:arial;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Friend funtions&lt;/span&gt; are funtions which are not the members of a class, but can access the private members of an instance of that class.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-1153141026631971728?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/1153141026631971728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/cc-common-interview-questions.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1153141026631971728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/1153141026631971728'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/02/cc-common-interview-questions.html' title='C/C++ Common interview questions'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-6231501039904155939</id><published>2009-01-30T19:29:00.001+05:00</published><updated>2009-01-30T19:32:44.343+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='un-initialized parameters'/><category scheme='http://www.blogger.com/atom/ns#' term='NULL'/><category scheme='http://www.blogger.com/atom/ns#' term='out parameters'/><title type='text'>Passing NULL as output parameter</title><content type='html'>Although it seems okay, but its not okay to pass a variable initialized with NULL as out parameter to a function.&lt;br /&gt;&lt;br /&gt;For example, I was doing this once upon a time&lt;br /&gt;SomeClass *objSomeClass = NULL;&lt;br /&gt;SomeFunction(objSomeClass);&lt;br /&gt;// where SomeFunction is supposed to return something in objSomeClass&lt;br /&gt;// This code is correct by syntax, but created problems for me.&lt;br /&gt;&lt;br /&gt;The right thing to do is&lt;br /&gt;&lt;br /&gt;SomeClass * objSomeClass = new SomeClass();&lt;br /&gt;SomeFunction(objSomeClass);&lt;br /&gt;&lt;br /&gt;cheers all...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-6231501039904155939?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/6231501039904155939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/01/passing-null-as-output-parameter.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6231501039904155939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/6231501039904155939'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/01/passing-null-as-output-parameter.html' title='Passing NULL as output parameter'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-8803192521517894983</id><published>2009-01-30T19:22:00.000+05:00</published><updated>2010-09-21T17:46:58.612+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Win32 Sockets'/><category scheme='http://www.blogger.com/atom/ns#' term='TCP/IP'/><category scheme='http://www.blogger.com/atom/ns#' term='Junk characters in recv return'/><category scheme='http://www.blogger.com/atom/ns#' term='Network Programming'/><title type='text'>More on Sockets</title><content type='html'>I was writing server side code which will be reading commands from a client over a Win32 socket, problematic code was like this&lt;br /&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;// suppose m_sock is a working socket, all we gotta do is start receiving data on it&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;const int nBuffSize = 256;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;int nRecv = 0;&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;char * szCmdBuff = new char [nBuffSize];&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(szCmdBuff, 0, nBuffSize);&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;while(1){&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;nRecv  = recv(m_sock, szCmdBuff, nBuffSize, 0);    &lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;// do something with the data&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(szCmdBuff, 0, nBuffSize);&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;}&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Problem &lt;/b&gt;created by this code: Junk values in input.&lt;br /&gt;&lt;b&gt;Solution&lt;/b&gt;: do memset right before calling recv&lt;br /&gt;&lt;br /&gt;Exact code to refresh things goes like this&lt;br /&gt;&lt;br /&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;while(1){&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(szCmdBuff, 0, nBuffSize);&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;nRecv  = recv(m_sock, szCmdBuff, nBuffSize, 0);    &lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;// do something with the data&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(szCmdBuff, 0, nBuffSize);&lt;/div&gt;&lt;div style="color: blue; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;}&lt;/div&gt;&lt;br /&gt;cheers all...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-8803192521517894983?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/8803192521517894983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/01/more-on-sockets.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/8803192521517894983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/8803192521517894983'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/01/more-on-sockets.html' title='More on Sockets'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-820837548505128567.post-5038688082476968642</id><published>2009-01-30T19:15:00.001+05:00</published><updated>2009-02-27T10:58:38.267+05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Win32 Sockets'/><category scheme='http://www.blogger.com/atom/ns#' term='Accept method'/><category scheme='http://www.blogger.com/atom/ns#' term='TCP/IP'/><category scheme='http://www.blogger.com/atom/ns#' term='Network Programming'/><title type='text'>Mistakes, not to be forgotten</title><content type='html'>Socket Programming:&lt;br /&gt;&lt;br /&gt;Was writing a socket server few days back. The code was not working, it goes like(omitting error checks)&lt;br /&gt;&lt;br /&gt;   &lt;span style="font-family:courier new;"&gt;SOCKET g_sock_server;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   g_sock_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   bind(g_sock_server, (LPSOCKADDR) &amp;amp;g_addr_server, sizeof(g_addr_server));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   listen(g_sock_server, SOMAXCONN);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        SOCKADDR_IN addr_cli;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        SOCKET s_cli;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        int nSize = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        s_cli = accept(g_sock_server, (LPSOCKADDR)&amp;amp;addr_cli, &amp;amp;nSize);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;        if(s_cli == INVALID_SOCKET) return;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      // rest of the code... say blah blah blah blah&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The method accept will always return INVALID_SOCKET, guess why?&lt;br /&gt;&lt;br /&gt;because of&lt;br /&gt;&lt;br /&gt;int nSize = 0;&lt;br /&gt;&lt;br /&gt;The fix is&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int nSize = sizeof(addr_cli)&lt;br /&gt;&lt;br /&gt;cheers all...&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/820837548505128567-5038688082476968642?l=aprogrammersday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprogrammersday.blogspot.com/feeds/5038688082476968642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aprogrammersday.blogspot.com/2009/01/mistakes-not-to-be-forgotten.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5038688082476968642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/820837548505128567/posts/default/5038688082476968642'/><link rel='alternate' type='text/html' href='http://aprogrammersday.blogspot.com/2009/01/mistakes-not-to-be-forgotten.html' title='Mistakes, not to be forgotten'/><author><name>Naeem Akram</name><uri>https://profiles.google.com/112413662164775764251</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-CXYzlP3V1WY/AAAAAAAAAAI/AAAAAAAABC8/xViu8mBaji4/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
