C Sorting PHP exec Tutorial

C Sorting PHP exec Tutorial

C Sorting PHP exec Tutorial

There’s another chapter to our C “sorting” program in addition to the “piping” functionality we added with C Sorting Command Line Piping Tutorial as shown below, a couple of days ago. And it’s a pretty important chapter if you are interested in software integration, and “meeting points”. We talk about the “meeting point” of web and desktop applications through the use of mechanisms with the web application server language’s world … our web server language today is PHP and its exec method, but it could be ASP.Net and a new Process() scenario if that’s how you roll … but it has to be Windows web hosting … as we do with some local web serving utilizing the brilliant EasyPHP local web server … we can’t show you live on rjmprogramming.com.au domain because it is a Linux web server.

Please don’t think everything is possible with this arrangement, and a designer of web functionality would be wary, so just play within reasonable restrictions, and you should be fine … but don’t know about you … but personally find this software integration interesting and exciting.

So today we show some (proof of concept) server side PHP taking a file_get_contents() original data source and uses some C executable, placed into the same directory as the PHP, in conjuction with the use of the exec() method to rearrange the order of the items of the original data via that C executable’s sorting functionality.

The programming C code you could call use_qsort.c changing from a couple of days ago as per this link shores up a bit of the data sophistication accepted.

The programming PHP code you could call use_qsort.php supervises the Digital Mars C executable that is created using the C code above.

Who says desktop work is irrelevant to web applications? After all, the server side languages interface to what the desktop world looks like … a web server operating system. It is worth remembering that no matter how “cloudy” things get there are still web servers at the end of all these trails.


Previous relevant C Sorting Command Line Piping Tutorial is shown below.

C Sorting Command Line Piping Tutorial

C Sorting Command Line Piping Tutorial

Hope you’ve been noticing the improved usefulness, as a tool, our C “sorting” program is becoming as, today, we add some “piping” functionality, to add to yesterday’s command line switch improvements with our Windows C program that sorts arguments on the command line via the qsort method when we presented C Sorting Command Line Switch Tutorial as shown below. We feature this blog post at WordPress 4.1.1 website also with C Sorting Command Line Piping Tutorial.

Today, before we get into the “piping” talk we want to show you one more switch we invent …

  1. /p … to either prompt the user for input data or read it from a file via a command like …

    type input.file | use_qsort /r /p Throw These In 2 The Mix

Out of the “nice to haves” we left you with yesterday we’ve decided to implement …

  • explanatory advice if no arguments were entered (as is likely in all innocence) by the user
  • control over the input and output (I/O … input/output) mechanisms … important for piping thoughts … we may talk more on this

… but left out of the picture … “allow for switches anywhere, rather than assuming they’ll be entered first (but again, the switch logic has your rules)” … c’est la vie … but you could improve it for this idea if you like?!

In this program, now, you may see the use of …

  • “piping” functionality, helped out by the “gets” function (and an understanding that input file records will always be different (again, you could improve?!)) so that the input data could come from (a mix of) …
    1. the command line arguments (as of previous incarnations) … and introduced as of this incarnation are …
    2. interactive input from the keyboard (we refer to this as “prompting” but this is a bit of a misnomer of a term … we don’t prompt as we want the output stream just to contain “findings”, not prompt strings … though, as we did with the “help” output (where we used the perror function to effectively write to the “2>” error output stream, with that) maybe you could write a prompt to the error output stream (will, again, leave that to you, perhaps?! … but for myself, I like a “clean” output data “sense”)
    3. read input data from a file via ” < [input.file] ” (or “type [input.file] | use_qsort /p”)

    … and (though no different to yesterday) you could also send the output to a file via ” > [output.file] “

  • system(cmd); // make it a command line scenario … enabling the “piping” (input data) world and the “command line argument” (input data) world to meet … again, a weakness is the limits on the amount of data this will work with … you could consider a system of writing to temporary files instead?! … up to you

  • qsort((void *)argv, (size_t)argc, sizeof(char *), &(*(int (*)(void const *, void const *))funcArr[mymode])); // unchanged from yesterday

What results is a pretty flexible program that is now a “tool” in the sense that it can interface to other command line tools and add its little bit of a “sorting” usefulness to the “equation” of your solution. After all, software is a collaborative process, always made up of parts.

The programming C code you could call use_qsort.c changing from yesterday as per this link.


Previous relevant C Sorting Command Line Switch Tutorial is shown below.

C Sorting Command Line Switch Tutorial

C Sorting Command Line Switch Tutorial

Yesterday we started with a Windows C program that sorts arguments on the command line via the qsort method when we presented C Sorting Primer Tutorial as shown below.

Today we show you a very useful technique to open up some functionality thoughts regards a command line program when we include some “homemade” switches. Say “homemade” because you decide what switch means what bit of program configuration takes place, so today we allow for two “homemade” switches to our program …

Today we show you a very useful technique to open up some functionality thoughts regards a command line program when we include some “homemade” switches. Say “homemade” because you decide what switch means what bit of program configuration takes place, so today we allow for two “homemade” switches to our program …

  1. /r … to reverse the sort (NB. Windows often uses “/” while Unix and Linux more often use “-” … by convention … but it doesn’t have to be this way if you program differently … as we said, you make the rules with your switches)
  2. /n … to sort numerically (rather than alphabetically)

Nice to haves … not done (yet) … would include …

  • explanatory advice if no arguments were entered (as is likely in all innocence) by the user
  • allow for switches anywhere, rather than assuming they’ll be entered first (but again, the switch logic has your rules)
  • control over the input and output (I/O … input/output) mechanisms … important for piping thoughts … we may talk more on this

In this program, now, you may see the use of …

  • function pointers … pointers that point at functions within your program code … cute, huh? … we talked about these, also, with Function Pointers in C and C++ Primer Tutorial and we also like this link … thanks

  • qsort((void *)argv, (size_t)argc, sizeof(char *), &(*(int (*)(void const *, void const *))funcArr[mymode]));

The programming C code you could call use_qsort.c changing from yesterday as per this link.


Previous relevant C Sorting Primer Tutorial is shown below.

C Sorting Primer Tutorial

C Sorting Primer Tutorial

As we have mentioned before, as with C String Function Timings Primer Tutorial as shown below, you don’t have to use an IDE to do C programming. There is Digital Mars C as an example of that. We have talked about the Xcode command line tools 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’d also like to add that Windows C programmers from the days of Microsoft C, who miss it (know I do … 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 (and with the WordPress 4.1.1 version C Sorting Primer Tutorial) …


qsort((void *)argv, (size_t)argc, sizeof(char *), isbigger);

… qsort … is available in Digital Mars C, as it used to work in Microsoft C.

We show it in action today sorting, alphabetically, command line arguments (on the Windows (DOS) command line doh!). It has the scope, with its interface to tailoring your own sorting “algorithm” function abilities, to be able to handle any type of business logic you choose, that “sorting” jobs so often ask for.

So … get … sorted … with our C code you could call use_qsort.c based on an idea out of a Microsoft C manual and Digital Mars compilable via (the taxing chortle, chortle) …


dmc use_qsort

… yes … no make files required here, nor IDE menus … but brush up on your pointers, perhaps.

As a Windows programming afficianardo would tell you … 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’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.


Previous relevant C String Function Timings Primer Tutorial is shown below.

C String Function Timings Primer Tutorial

C String Function Timings Primer Tutorial

You don’t have to use an IDE to do C programming. There is Digital Mars C as an example of that. We have talked about the Xcode command line tools 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.

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 Digital Mars C) and run this tutorial’s download at a Windows Command Line (prompt) you will see how fast C is, working way down there near the kernel level. So the second accuracy of time(NULL) won’t pass muster for the timings, and instead, here, we use the clock() 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() … personally, I’m affronted, gobsmacked, insulted, resigned … impersonally, I’m anti-affronted, anti-gobsmacked, anti-insulted, anti-resigned … the nearby ants, antily-anti-affronted, antily-anti-gobsmacked, antily-anti-insulted, antily-anti-resigned.

So feel free to download the C programming source code here and rename it to timings.c

Hope you enjoy this tutorial showing you some command line C dmc (Digital Mars) compilation work.

A really helpful tutorial for code above to do with using clock() is shown here … thanks.

A really helpful tutorial for C string functionality via string.h is shown here … thanks.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

23 Responses to C Sorting PHP exec Tutorial

  1. Kala says:

    Hello! I completely consent with the previous comment. I really love it site and I like studying it for 6 days. I can not end doing it! Hehe. I guess, it is my habit nowadays!

  2. Undeniably believe that which you stated. Your beloved purpose seemed to be over the internet the easiest thing to be aware of. I say to you, I definitely get annoyed while people today think of worries that they just donโ€™t know about. You managed to hit the nail upon the leading as well as defined out the whole factor with no obtaining side effect , persons can take a signal. Will most likely be back to get extra. Thanks

  3. I adore foregathering beneficial data , this post has got me even a lot more information! .

  4. Thanks for sharing superb informations. Your web site is very cool. I am impressed by the details that you have on this website. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found simply the info I already searched everywhere and just could not come across. What a perfect website.

  5. You made some nice points there. I did a search on the matter and found most folks will consent with your blog.

  6. hair care says:

    topics as well as discuss it with us. I believe it will help a lot of individuals. Thanks

  7. finance blog says:

    subjects and share it with us. I think it will certainly assist a great deal of some people. Many thanks

  8. fantastic points altogether, you just received a brand new reader. What would you recommend in regards to your publish that you simply made a few days in the past? Any certain?|

  9. Great post. I was checking continuously this blog and I am impressed! Very useful info particularly the last part :) I care for such information much. I was looking for this particular info for a very long time. Thank you and good luck.

  10. I relish, cause I found just what I used to be taking a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  11. Wonderful site. Lots of useful information here. I am sending it to some friends ans also sharing in delicious. And of course, thanks in your sweat!

  12. Remodeling says:

    Thanks a lot for giving everyone a very brilliant chance to discover important secrets from this blog. It can be very fantastic and stuffed with a great time for me and my office mates to search your web site at least 3 times per week to study the newest stuff you have. And lastly, we are actually impressed concerning the astonishing opinions you give. Certain 1 facts in this posting are definitely the most efficient I’ve ever had.

  13. I precisely needed to thank you so much all over again. I am not sure what I would’ve gone through in the absence of the type of aspects revealed by you over such a problem. This has been a daunting difficulty in my opinion, however , viewing your specialized tactic you managed it forced me to jump for delight. Now i’m thankful for the work and then wish you recognize what a powerful job you have been undertaking educating the mediocre ones using your website. I am sure you have never come across all of us.

  14. arcade games says:

    I definitely wanted to develop a comment so as to express gratitude to you for some of the magnificent solutions you are giving out on this website. My rather long internet look up has at the end of the day been rewarded with useful ideas to exchange with my classmates and friends. I would assert that we site visitors actually are unquestionably endowed to dwell in a magnificent community with so many marvellous professionals with interesting tips. I feel somewhat privileged to have used your webpage and look forward to many more fun minutes reading here. Thanks a lot once again for all the details.

  15. Iยกยฆve recently started a web site, the information you provide on this web site has helped me greatly. Thank you for all of your time & work.

  16. inquiry says:

    But wanna remark that you have a very decent site, I the design and style it really stands out.

  17. As I web site possessor I believe the content material here is rattling excellent , appreciate it for your hard work. You should keep it up forever! Good Luck.

  18. have says:

    Truly appreciate the admission you made available.. Very helpful perspective, many thanks for posting.. My personal internet searching seem total.. thanks. Is not it great once you obtain a fantastic publish?

  19. Cabinet says:

    great points altogether, you simply won a new reader. What would you recommend in regards to your put up that you simply made some days in the past? Any positive?

  20. pass says:

    certainly, study is paying off. Supporting the piece of writing.. best wishes Amazingly valuable viewpoint, appreciate your sharing.. Genuinely valuable outlook, thank you for sharing..

  21. I enjoy you because of all your efforts on this web site. My mother take interest in getting into research and it is easy to understand why. A lot of people know all of the dynamic method you provide reliable guides by means of your web blog and therefore welcome participation from some others on that situation then my girl is always discovering a whole lot. Take pleasure in the rest of the year. You have been doing a tremendous job.

  22. Youre so cool! I dont suppose Ive read anything in this way before. So good to uncover somebody with some original tips on this topic. realy appreciate starting this up. this excellent website is something that is necessary more than the internet, a person if we do originality. valuable function for bringing something new towards the web!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>