{"id":16078,"date":"2015-07-21T05:01:01","date_gmt":"2015-07-20T19:01:01","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=16078"},"modified":"2015-07-20T14:13:24","modified_gmt":"2015-07-20T04:13:24","slug":"c-sorting-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-sorting-primer-tutorial\/","title":{"rendered":"C Sorting Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/use_qsort.JPG\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C Sorting Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/use_qsort.JPG\" title=\"C Sorting Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C Sorting Primer Tutorial<\/p><\/div>\n<p>As we have mentioned before, as with <a target=_blank title='C String Function Timings Primer Tutorial' href='#csftpt'>C String Function Timings Primer Tutorial<\/a> as shown below, you don&#8217;t have to use an IDE to do C programming.  There is <a target=_blank title='Digital Mars' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars'>Digital Mars<\/a> C as an example of that.   We have talked about the <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5519'>Xcode command line tools<\/a> before, that frees the gcc compiler to (also) be a command line tool to write C programs from the command line separate to any IDE usage, and we&#8217;d also like to add that Windows C programmers from the days of Microsoft C, who miss it (know I do &#8230; it was solid), can still write some of this code using Digital Mars C.  Luckily, one of the most useful functions, as exemplified by the C code line below &#8230;<\/p>\n<p><code><br \/>\n qsort((void *)argv, (size_t)argc, sizeof(char *), isbigger);<br \/>\n<\/code><\/p>\n<p> &#8230; qsort &#8230; is available in Digital Mars C, as it used to work in Microsoft C.<\/p>\n<p>We show it in action today sorting, alphabetically, command line arguments (on the Windows (DOS) command line <font size=1>doh!<\/font>).  It has the scope, with its interface to tailoring your own sorting &#8220;algorithm&#8221; function abilities, to be able to handle any type of business logic you choose, that &#8220;sorting&#8221; jobs so often ask for.<\/p>\n<p>So &#8230; get &#8230; sorted &#8230; with our C code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/use_qsort.c_GETME\" title='use_qsort.c'>use_qsort.c<\/a> based on an idea out of a Microsoft C manual and Digital Mars compilable via (the taxing <font size=1>chortle, chortle<\/font>) &#8230;<\/p>\n<p><code><br \/>\n dmc use_qsort<br \/>\n<\/code><\/p>\n<p> &#8230; yes &#8230; no make files required here, nor IDE menus &#8230; but brush up on your <a target=_blank title='Pointers information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Pointer_(computer_programming)'>pointers<\/a>, perhaps.<\/p>\n<p>As a Windows programming afficianardo would tell you &#8230; desktop functionality opens you up to many scheduling and batch mode processing ideas often crucial to the best productivity tools in software.  It is no wonder that the web&#8217;s curl is so popular so that a bit of these software strengths from the desktop days can be brought to bear on the web application world we increasingly encounter today.<\/p>\n<hr>\n<p id='csftpt'>Previous relevant <a target=_blank title='C String Function Timings Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/c-string-function-timings-primer-tutorial\/'>C String Function Timings Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings_c.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C String Function Timings Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings_c.jpg\" title=\"C String Function Timings Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C String Function Timings Primer Tutorial<\/p><\/div>\n<p>You don&#8217;t have to use an IDE to do C programming.  There is <a target=_blank title='Digital Mars' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars'>Digital Mars<\/a> C as an example of that.   We have talked about the <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5519'>Xcode command line tools<\/a> before, that frees the gcc compiler to (also) be a command line tool to write C programs from the command line separate to any IDE usage.<\/p>\n<p>So it is today with this tutorial, where we work with Digital Mars C, to time some inhouse and C string library (string.h) library string manipulation functionality.   If you get to compile (recommend <a target=_blank title='Digital Mars download page' href='http:\/\/www.digitalmars.com\/'>Digital Mars C<\/a>) and run this tutorial&#8217;s download at a Windows Command Line (prompt) you will see how fast C is, working way down there near the <a target=_blank title='kernel information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Kernel_%28computing%29'>kernel<\/a> level.   So the second accuracy of <i>time(NULL)<\/i> won&#8217;t pass muster for the timings, and instead, here, we use the <i>clock()<\/i> functionality to get the refinement required to have it mean anything.   Could be affected by so many other things anyway, like what else is running, but is instructive as to what you might have thought was the fastest method.   Personally, love using strstr() to find strings within strings, but, as you can see from the numbers, there are better choices such as strchr() and strpbrk() &#8230; personally, I&#8217;m affronted, gobsmacked, insulted, resigned &#8230; impersonally, I&#8217;m anti-affronted, anti-gobsmacked, anti-insulted, anti-resigned &#8230; the nearby ants,  antily-anti-affronted, antily-anti-gobsmacked, antily-anti-insulted, antily-anti-resigned.<\/p>\n<p>So feel free to download the C programming source code here and rename it to <a target=_blank title='timings.c' href='http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings.c_GETME'>timings.c<\/a><\/p>\n<p>Hope you enjoy this <a target=_blank title=\"Digital Mars compiling\" href=\"http:\/\/www.rjmprogramming.com.au\/C\/string_timings\/timings_c.jpg\">tutorial<\/a> showing you some command line C dmc (Digital Mars) compilation work.<\/p>\n<p>A really helpful tutorial for code above to do with using clock() is shown <a target=_blank title='Good tutorial 1' href='http:\/\/www.tutorialspoint.com\/c_standard_library\/c_function_clock.htm'>here<\/a> &#8230; thanks.<\/p>\n<p>A really helpful tutorial for C string functionality via string.h is shown <a target=_blank title='Good tutorial 2' href='http:\/\/www.cplusplus.com\/reference\/cstring\/'>here<\/a> &#8230; thanks.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d6788' onclick='var dv=document.getElementById(\"d6788\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Digital+Mars\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d6788' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d16078' onclick='var dv=document.getElementById(\"d16078\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=c\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d16078' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As we have mentioned before, as with C String Function Timings Primer Tutorial as shown below, you don&#8217;t have to use an IDE to do C programming. There is Digital Mars C as an example of that. We have talked &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-sorting-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[176,234,235,319,331,358,1638,1637,997,1636,1173,1319,1435],"class_list":["post-16078","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-c","tag-command-line","tag-command-line-arguments","tag-desktop","tag-digital-mars","tag-dos","tag-microsoft-c","tag-pointers","tag-programming","tag-qsort","tag-sort","tag-tutorial","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/16078"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=16078"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/16078\/revisions"}],"predecessor-version":[{"id":16095,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/16078\/revisions\/16095"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=16078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=16078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=16078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}