{"id":65513,"date":"2024-11-10T03:01:00","date_gmt":"2024-11-09T17:01:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=65513"},"modified":"2024-11-10T16:52:30","modified_gmt":"2024-11-10T06:52:30","slug":"php-recompiles-c-numerical-sort-genericization-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-recompiles-c-numerical-sort-genericization-tutorial\/","title":{"rendered":"PHP Recompiles C Numerical Sort Genericization Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Recompiles C Numerical Sort Genericization Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/more_srt.jpg\" title=\"PHP Recompiles C Numerical Sort Genericization Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Recompiles C Numerical Sort Genericization Tutorial<\/p><\/div>\n<p>We come at improving yesterday&#8217;s <a title='PHP Recompiles C Numerical Bubble Sort Tutorial' href='#phprcnbst'>PHP Recompiles C Numerical Bubble Sort Tutorial<\/a> two ways, today, they being &#8230;<\/p>\n<ol>\n<li>genericization &#8230; taking the form of changing a hardcoding in a dropdown and associated variable &#8220;remix&#8221; regarding the functionality of the &#8220;what we should now call just&#8221; Numerical Sort web application &#8230; and &#8230;<\/li>\n<li>simple defensive programming &#8230; where code can get to the operating system, as with serverside languages such as PHP and compiled programs like we&#8217;re doing here with C then care is needed<\/li>\n<\/ol>\n<p>By &#8220;genericization&#8221; we&#8217;re taking the &#8220;bubble&#8221; out of <strike>&#8220;squeak&#8221;<\/strike> &#8220;bubble sort&#8221; to just leave &#8220;sort&#8221; with our thinking, though we&#8217;d like to restrict the sorting to &#8220;numerical sorting&#8221; ideas.  In other words, we&#8217;ve channelled the excellent C code bases at <a target=\"_blank\" href='https:\/\/www.w3schools.com\/dsa' rel=\"noopener\">W3schools<\/a>, thanks, for more than just a &#8220;bubble sort&#8221; and left it up to the PHP to see what has been &#8220;plonked&#8221; C wise by us to develop a dropdown $selsorttype PHP variable containing a genericized outerHTML, rather than the previous &#8220;bubble_sort&#8221; hardcoding used &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n  $sorttype=\"bubble_sort\";<br \/>\n  $selsorttype=\"bubble_sort\";<br \/>\n  <br \/>\n  $ccont=\"\";<br \/>\n  $lastresult=\"\";<br \/>\n<br \/>\n  if (isset($_POST['mysort'])) {<br \/>\n    $sorttype=str_replace('+',' ',urldecode($_POST['mysort']));<br \/>\n    $ccont=file_get_contents('.\/' . $sorttype . '.c');<br \/>\n  } else if (isset($_GET['mysort'])) {<br \/>\n    $sorttype=str_replace('+',' ',urldecode($_GET['mysort']));<br \/>\n    $ccont=file_get_contents('.\/' . $sorttype . '.c');<br \/>\n  } else {<br \/>\n    $ccont=file_get_contents('.\/bubble_sort.c');<br \/>\n  }<br \/>\n  <br \/>\n  foreach (glob('*_sort.c') as $filename) {<br \/>\n    if (strpos(basename($filename), 'new_') === false) {<br \/>\n    if ($selsorttype == \"bubble_sort\") {<br \/>\n       $selsorttype=\"&lt;select onchange=\\\"location.href='.\/bubble_sort_c.php?mysort=' + this.value;\\\" style=display:inline-block; name=\\\"mysort\\\" id=\\\"mysort\\\"&gt;&lt;option value='\" . explode('.',basename($filename))[0] . \"'&gt;\" . explode('.',basename($filename))[0] . \"&lt;\/option&gt;&lt;\/select&gt;\";<br \/>\n    } else if (basename($filename) == ($sorttype . \".c\")) {<br \/>\n       $selsorttype=str_replace(\" id=\\\"mysort\\\"&gt;\", \" id=\\\"mysort\\\"&gt;\" . \"&lt;option value='\" . explode('.',basename($filename))[0] . \"'&gt;\" . explode('.',basename($filename))[0] . \"&lt;\/option&gt;\", $selsorttype);<br \/>\n    } else {<br \/>\n       $selsorttype=str_replace(\"&lt;\/select&gt;\", \"&lt;option value='\" . explode('.',basename($filename))[0] . \"'&gt;\" . explode('.',basename($filename))[0] . \"&lt;\/option&gt;&lt;\/select&gt;\", $selsorttype);<br \/>\n    }<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p>Why worry about &#8220;simple defensive programming&#8221;?  Some users might be looking for loopholes in your code to exploit what the underlying programming language used is capable of, and that can be altering file systems.  What if it was possible in that &#8220;what we hope&#8221; is a user supplied numerical comma separated list, somebody was able to embed some operating system call?  Well, we figure that malicious idea would have to contain a quote or double quote, <font color=blue>so now we have<\/font> &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n  $prefix=explode(' = {', $ccont)[0] . ' = {';<br \/>\n  $midbit=<font color=blue>explode('\"',explode(\"'\",<\/font>explode('}', explode($prefix, $ccont)[1])[0]<font color=blue>)[0])[0]<\/font>;<br \/>\n  $suffix=explode($prefix . $midbit, $ccont)[1];<br \/>\n  <br \/>\n  $altmidbit=$midbit;<br \/>\n<br \/>\n  $httpis=\" http\";<br \/>\n  $endaf=\"youllveverfindthis\";<br \/>\n  $endat=\"youllveverfindthis\";<br \/>\n  $hbits=explode(' http', $prefix);<br \/>\n  if (sizeof($hbits) &gt; 1) {<br \/>\n    $endaf=' http' . explode(' ', $hbits[1])[0];<br \/>\n    $endat=' http' . explode(' ', $hbits[1])[0] . '&lt;\/a&gt;';<br \/>\n    $httpis=$endaf;<br \/>\n  }<br \/>\n <br \/> <br \/>\n  if (isset($_POST['myarr'])) {<br \/>\n     $altmidbit=<font color=blue>str_replace('   ',' + ',<\/font>str_replace('+',' ',urldecode($_POST['myarr']))<font color=blue>)<\/font>;<br \/>\n     file_put_contents('new_' . $sorttype . '.c', $prefix . <font color=blue>explode('\"',explode(\"'\",<\/font>$altmidbit<font color=blue>)[0])[0]<\/font> . $suffix);<br \/>\n     exec('gcc new_' . $sorttype . '.c -o ' . $sorttype);<br \/>\n     $lastresult='$ gcc new_' . $sorttype . '.c -o ' . $sorttype . ' &lt;br&gt;$ .\/' . $sorttype . '&lt;br&gt;';<br \/>\n     $lastresult.=shell_exec('.\/' . $sorttype);<br \/>\n     $midbit=$altmidbit;<br \/>\n  } else if (isset($_GET['myarr'])) {<br \/>\n     $altmidbit=<font color=blue>str_replace('   ',' + ',<\/font>str_replace('+',' ',urldecode($_GET['myarr']))<font color=blue>)<\/font>;<br \/>\n     file_put_contents('new_' . $sorttype . '.c', $prefix . <font color=blue>explode('\"',explode(\"'\",<\/font>$altmidbit<font color=blue>)[0])[0]<\/font> . $suffix);<br \/>\n     exec('gcc new_' . $sorttype . '.c -o ' . $sorttype);<br \/>\n     $lastresult='$ gcc new_' . $sorttype . '.c -o ' . $sorttype . ' &lt;br&gt;$ .\/' . $sorttype . '&lt;br&gt;';<br \/>\n     $lastresult.=shell_exec('.\/' . $sorttype);<br \/>\n     $midbit=$altmidbit;<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p> &#8230; used in <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php-GETME\" rel=\"noopener\">fortified<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php--GETME\" rel=\"noopener\">and genericized<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php--GETME\" rel=\"noopener\">bubble_sort_c.php<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php\" rel=\"noopener\">Numerical Sort<\/a> web application.<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>(&#8220;Simple defensive programming&#8221; x 786) &#8211; ((Paranoid tendency factor) x 56) might get you to want to research <a target=\"_blank\" title='Captive portal information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Captive_portal' rel=\"noopener\">Captive portals<\/a> &#8230; and beyond!<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/php-recompiles-c-numerical-sort-genericization-tutorial\/' rel=\"noopener\">PHP Recompiles C Numerical Sort Genericization Tutorial<\/a> ...<\/p-->\n<hr>\n<p id='phprcnbst'>Previous relevant <a target=\"_blank\" title='PHP Recompiles C Numerical Bubble Sort Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-recompiles-c-numerical-bubble-sort-tutorial\/' rel=\"noopener\">PHP Recompiles C Numerical Bubble Sort Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP Recompiles C Numerical Bubble Sort Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort.gif\" title=\"PHP Recompiles C Numerical Bubble Sort Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Recompiles C Numerical Bubble Sort Tutorial<\/p><\/div>\n<p>For years and years, before the Internet, there were <font size=1>(and still are)<\/font> the publicly accessible desktop application worlds of &#8230;<\/p>\n<ul>\n<li>Windows with command line DOS<\/li>\n<li>Mac with command line (a lot like, but not exactly) Linux<\/li>\n<\/ul>\n<p> &#8230; and in either of these woooorrrllldddsss, or within any Unix or Linux environment, for years and years the <a target=\"_blank\" title='C information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/C_(programming_language)' rel=\"noopener\">C<\/a> programming language was a big programming language presence.<\/p>\n<p>We&#8217;re hooking into this C programming today because up at our AlmaLinux web server we have the <a target=\"_blank\" title='gcc compiler information' href='https:\/\/gcc.gnu.org\/' rel=\"noopener\">gcc<\/a> (ie. GNU Compiler Collection) compiler available to compile C code into an executable program.<\/p>\n<p>And we didn&#8217;t argue with the great Numerical Bubble Sort C code basis we visited at <a target=\"_blank\" href='https:\/\/www.w3schools.com\/dsa\/trydsa.php?filename=demo_bubblesort' rel=\"noopener\">W3schools<\/a>, thanks, and so we&#8217;re allowing users to &#8230;<\/p>\n<ul>\n<li>tweak that code &#8230; ie. we&#8217;d be mad not to control the bulk of what a user can do &#8230; so that &#8230;<\/li>\n<li>a user can add their own integer comma separated array list &#8230; our PHP &#8230;<\/li>\n<li>creates a new_bubble_sort.c &#8230; and as the PHP explains &#8230;<\/li>\n<li>use PHP exec and shell_exec to &#8230;<br \/>\n<code><br \/>\n$ gcc new_bubble_sort.c -o bubble_sort<br \/>\n$ .\/bubble_sort<br \/>\n<\/code>\n<\/li>\n<li>outputting a sorted array result<\/li>\n<\/ul>\n<p> &#8230; further to that discussion back with <a title='CSH\/KSH\/PHP Numerical Bubble Sort Tutorial' href='#csh\/ksh\/phpnbst'>CSH\/KSH\/PHP Numerical Bubble Sort Tutorial<\/a>, some time ago now, going along the same lines.<\/p>\n<p>See &#8230;<\/p>\n<ul>\n<li>PHP <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php_GETME\" rel=\"noopener\">bubble_sort_c.php<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort_c.php\" rel=\"noopener\">Numerical Bubble Sort<\/a> &#8230; overseeing &#8230;<\/li>\n<li>C <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/bubble_sort.c_GETME\" rel=\"noopener\">bubble_sort.c<\/a> &#8230; as a C code basis<\/li>\n<\/ul>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/php-recompiles-c-numerical-bubble-sort-tutorial\/' rel=\"noopener\">PHP Recompiles C Numerical Bubble Sort Tutorial<\/a>.<\/p-->\n<hr>\n<p id='csh\/ksh\/phpnbst'>Previous relevant <a target=\"_blank\" title='CSH\/KSH\/PHP Numerical Bubble Sort Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/csh\/ksh\/php-numerical-bubble-sort-tutorial\/' rel=\"noopener\">CSH\/KSH\/PHP Numerical Bubble Sort Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=25&#038;jmin=1&#038;jmax=295&#038;imode=0\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"CSH\/KSH\/PHP Numerical Bubble Sort Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/csh_sort.jpg\" title=\"CSH\/KSH\/PHP Numerical Bubble Sort Tutorial\"  id=\"qwqtoijximpept\" onmouseover=\" this.src=this.src.replace('.png','.JPG').replace('.jpg','.png').replace('.JPG','.jpg'); \"  \/><\/a><p class=\"wp-caption-text\">CSH\/KSH\/PHP Numerical Bubble Sort Tutorial<\/p><\/div>\n<p>Here is a tutorial that follows up on yesterday&#8217;s <a target=\"_blank\" href='#cxnbst' title='C++ Xcode Numerical Bubble Sort Tutorial' rel=\"noopener\">C++ Xcode Numerical Bubble Sort Tutorial<\/a> as shown below, in an <i>&#8220;oh, I forgot&#8221;<\/i> moment to make the link between the programming language C (and then C++) and its relationship to the Linux or unix shell scripting environment C Shell (we&#8217;ll be saying <i>CSH<\/i>) (ie. today we go from a compiling language to an interpretive <i>scripting<\/i> set of languages), and CSH&#8217;s relationship with (the remarkable, the wonderful, the stupendous) <a target=\"_blank\" title='Linux awk ... programming language ... command' href='http:\/\/how-to.linuxcareer.com\/learning-linux-commands-awk' rel=\"noopener\"><i>awk<\/i><\/a>, making functionality like numerical sorts quite easy just using shell scripting functionality.   Well, that&#8217;s how it started with work on the Linux command line here on this Mac laptop using the Terminal application.  But, and am so very very very sorry to start a sentence with but &#8230; but, well you see there&#8217;s this &#8230; but I digress &#8230; I thought this could become a webpage or web application pretty easily by involving our old favourite PHP\/exec combination (with code rewritten for Korn Shell (we&#8217;ll be saying <i>KSH<\/i>)), because the rjmprogramming.com.au domain prefers KSH Korn shell &#8230; so we proceeded along those lines &#8230; and then lo and behold, it was apparent this could also be written for all the three PHP <i>&#8220;modes of use&#8221;<\/i> (latest <i>&#8220;foot in the door&#8221;<\/i> tutorial for this would be <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10515' title='PHP Modes of Use File Traverse Tutorial' rel=\"noopener\">PHP Modes of Use File Traverse Tutorial<\/a>) we&#8217;ve been talking about here lately at this blog &#8230; namely PHP used with <i>curl<\/i> and the <i>command line<\/i> usage and the <i>web browser<\/i> usage.<\/p>\n<p>Attempting to write code with a generic eye has the advantage that you end up with more flexibility, and, usually, more readable code.<\/p>\n<p>So in the <i>CSH<\/i> <i>scripting<\/i> code you&#8217;ll (need, maybe, to open up execute privileges via a command like <i><a target=\"_blank\" title='chmod information from computerhope ... thanks' href='http:\/\/www.computerhope.com\/unix\/uchmod.htm' rel=\"noopener\">chmod<\/a> 755 .\/bubble_sort.*sh<\/i> and) see:<\/p>\n<ul>\n<li>The use of <a target=\"_blank\" title='set' href='http:\/\/en.wikibooks.org\/wiki\/C_Shell_Scripting\/Variables' rel=\"noopener\">set<\/a> via <i>set variable=value<\/i> syntax &#8230; will fit in with all those lovers of interpretive languages (who like to add <i>$<\/i> &#8230; (who doesn&#8217;t?))<\/li>\n<li>The use of <a target=\"_blank\" title='Command line arguments' href='http:\/\/en.wikibooks.org\/wiki\/C_Shell_Scripting\/Parameters' rel=\"noopener\">Command line arguments<\/a> as with <i>.\/bubble_sort.csh 22 2 15 0<\/i> &#8230; adds to the flexibility of your code with the user being able to tailor each usage of the script<\/li>\n<li>The CSH (and very C like) way of incrementing <a target=\"_blank\" title='Incrementing values' href='http:\/\/www-cs.canisius.edu\/ONLINESTUFF\/UNIX\/shellprogramming.html#H' rel=\"noopener\">numerical variables<\/a> via <i>@ variable++<\/i> syntax<\/li>\n<li>The use of the underlying Linux operating system command to (numerically) sort (ie. <a target=\"_blank\" title='Linux sort' href='http:\/\/lowfatlinux.com\/linux-sort.html' rel=\"noopener\"><i>sort -n[r]<\/i><\/a>) &#8230; whether it uses a <a target=\"_blank\" title='Bubble sort information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Bubble_sort' rel=\"noopener\">&#8220;bubble sort&#8221;<\/a> am not totally sure &#8230; but if not try the <a target=\"_blank\" title='Buble ... sort ...' href='http:\/\/www.greatsong.net\/MUSIQUE-MICHAEL-BUBLE-IL-SORT-UN-ALBUM-DE-NOEL-28605.html' rel=\"noopener\">&#8220;buble sort&#8221;<\/a> &#8230; chortle, chortle<\/li>\n<li>The deliberate pointing out of any important restriction should there be one &#8230; doh! &#8230; in that we have a stipulation for a numerical data sort<\/li>\n<\/ul>\n<p>Found this <a target=\"_blank\" title='C shell link ... thanks' href='https:\/\/bima.astro.umd.edu\/checker\/node22.html#369' rel=\"noopener\">link<\/a> very useful for C shell (ie. CSH) research &#8230; thanks.<\/p>\n<p>Link to some downloadable CSH programming code &#8230; rename to <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.csh_GETME' title='bubble_sort.csh' rel=\"noopener\">bubble_sort.csh<\/a> &#8230; okay at Linux command line at this Mac, at least &#8230; but for rjmprogramming.com.au web server usage needed &#8230;<\/p>\n<p>Link to some downloadable KSH programming code &#8230; rename to <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.ksh_GETME' title='bubble_sort.ksh' rel=\"noopener\">bubble_sort.ksh<\/a> &#8230; the differences described by <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.csh-GETME' title='CSH vs KSH' rel=\"noopener\">bubble_sort.csh<\/a><\/p>\n<p>Link to some downloadable PHP programming code &#8230; rename to <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php_GETME' title='bubble_sort.php' rel=\"noopener\">bubble_sort.php<\/a> &#8230; which can supervise <i>bubble_sort.ksh<\/i> above using PHP <a target=\"_blank\" title='PHP exec command' href='http:\/\/php.net\/manual\/en\/function.exec.php' rel=\"noopener\"><i>exec<\/i><\/a> command in the, aforementioned, <i>&#8220;modes of use&#8221;<\/i>:<\/p>\n<ol>\n<li>Via http transport layer (ie. web browsing, or &#8220;surfing the net&#8221;) in an <a target=\"_blank\" title='Internet information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Internet' rel=\"noopener\">Internet<\/a> mode of use (eg: <a target=\"_blank\" title='Web browser usage' href='http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=12&#038;jmin=37&#038;jmax=82&#038;imode=0' rel=\"noopener\"><i>http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=12&#038;jmin=37&#038;jmax=82&#038;imode=0<\/i><\/a>) in address bar of a web browser<\/li>\n<li style='color:brown;'>Via <a target=\"_blank\" title='PHP information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/CURL' rel=\"noopener\">curl<\/a> in an Internet mode of use (eg. <i>curl http:\/\/www.rjmprogramming.com.au\/Linux\/awk\/csh\/bubble_sort.php?jsize=12@37@82@0<\/i>) at Linux or unix or Windows command line <\/li>\n<li style='color:blue;'>Via command line PHP in Linux or unix or Windows command line in a command or <a target=\"_blank\" title='Intranet information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Intranet' rel=\"noopener\">Intranet<\/a> mode of use (eg. <i>php .\/bubble_sort.php 12 37 82 0<\/i>) at a Linux or unix or Windows command line <\/li>\n<\/ol>\n<hr \/>\n<p id='cxnbst'>Previous relevant <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=10679' title='C++ Xcode Numerical Bubble Sort Tutorial' rel=\"noopener\">C++ Xcode Numerical Bubble Sort Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/sort\/CPlusPlus_sort.png\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C++ Xcode Numerical Bubble Sort Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/sort\/CPlusPlus_sort.png\" title=\"C++ Xcode Numerical Bubble Sort Tutorial\"  id=\"qtoijximpept\" onmouseover=\" this.src=this.src.replace('.jpg','.JPEG').replace('.png','.jpg').replace('.gif','.png').replace('.jpeg','.gif').replace('.JPEG','.jpeg'); \"  \/><\/a><p class=\"wp-caption-text\">C++ Xcode Numerical Bubble Sort Tutorial<\/p><\/div>\n<p>Here is a tutorial that uses the Xcode IDE on a Mac laptop to create a C++ desktop compiled application using a Bubble Sort method to numerically sort some numbers (ie. <i>double<\/i>).<\/p>\n<p>Attempting to write code with a generic eye has the advantage that you end up with more flexibility, and, usually, more readable code.<\/p>\n<p>Some ideas used in today&#8217;s code include:<\/p>\n<ul>\n<li>The use of <a target=\"_blank\" title='Preprocessor directives' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/preprocessor\/' rel=\"noopener\">Preprocessor directives<\/a> via <i>#define identifier replacement<\/i> syntax &#8230; will fit in with all those lovers of interpretive languages<\/li>\n<li>The use of <a target=\"_blank\" title='Command line arguments' href='http:\/\/www.cplusplus.com\/forum\/beginner\/5404\/' rel=\"noopener\">Command line arguments<\/a> as with <i>.\/Test 22 2 15 0<\/i> &#8230; adds to the flexibility of your code with the user being able to tailor each usage of the executable<\/li>\n<li>The use of a <a target=\"_blank\" title='Pointer' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/pointers\/' rel=\"noopener\">pointer<\/a> to an array within a function, meaning that the data can be changed (ie. sorted) in situ rather than returning a value (or resorting to a global variable array) &#8230; hence we use <i>void numerically_sort_array(double* asort, int isize = ASIZE, bool ascending = (SMODE != 0))<\/i> &#8230; you could change the <i>void<\/i> return, to return an error code, for example<\/li>\n<li>The C++ use of <a target=\"_blank\" title='Function default values' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/functions\/#defaultvalues' rel=\"noopener\">default values in parameters<\/a> of the function call, making use of the Preprocessor directives, so that the call could make sense as <i>numerically_sort_array(psarray);<\/i> as <i>numerically_sort_array(psarray, 1000, true);<\/i> &#8230; such thoughts come into play, in C++, also when considering <a target=\"_blank\" title='Overloading and templates' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/functions2\/' rel=\"noopener\">Overloading<\/a><\/li>\n<li>The deliberate pointing out of any important restriction should there be one &#8230; doh! &#8230; in that we have a stipulation for a <a target=\"_blank\" title='C++ basic data type' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/variables\/#fundamental' rel=\"noopener\"><i>double<\/i><\/a> data type array &#8230; and have not implemented any  <a target=\"_blank\" title='Overloading and templates' href='http:\/\/www.cplusplus.com\/doc\/tutorial\/functions2\/' rel=\"noopener\">Template<\/a> functionality, on this occasion<\/li>\n<\/ul>\n<p>Link to some downloadable C++ programming code &#8230; rename to <a target=\"_blank\" href='http:\/\/www.rjmprogramming.com.au\/CPlusPlus\/sort\/main.cpp_GETME' title='Download me' rel=\"noopener\">main.cpp<\/a> for use.<\/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='#d10679' onclick='var dv=document.getElementById(\"d10679\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=C%2B%2B\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10679' 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='#d10695' onclick='var dv=document.getElementById(\"d10695\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d10695' 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='#d65503' onclick='var dv=document.getElementById(\"d65503\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/tag\/sort\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d65503' 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='#d65513' onclick='var dv=document.getElementById(\"d65513\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/tag\/genericization\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d65513' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We come at improving yesterday&#8217;s PHP Recompiles C Numerical Bubble Sort Tutorial two ways, today, they being &#8230; genericization &#8230; taking the form of changing a hardcoding in a dropdown and associated variable &#8220;remix&#8221; regarding the functionality of the &#8220;what &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-recompiles-c-numerical-sort-genericization-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,33,37],"tags":[53,103,176,4988,4989,1849,2531,234,242,3616,4987,320,327,367,405,478,2537,1839,3362,710,885,932,969,996,997,1122,3942,3304,1319],"class_list":["post-65513","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-software","category-tutorials","tag-access","tag-array","tag-c","tag-captive","tag-captive-portal","tag-coding","tag-comma-separated-values","tag-command-line","tag-compiler","tag-defence","tag-defensive","tag-desktop-application","tag-did-you-know","tag-dropdown","tag-exec","tag-gcc","tag-generic","tag-genericization","tag-hardcoding","tag-list","tag-operating-system-2","tag-php","tag-portal","tag-program","tag-programming","tag-server","tag-shell_exec","tag-token","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/65513"}],"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=65513"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/65513\/revisions"}],"predecessor-version":[{"id":65541,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/65513\/revisions\/65541"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=65513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=65513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=65513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}