C Sorting ASP.Net Primer Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

C Sorting ASP.Net Primer Tutorial

C Sorting ASP.Net Primer Tutorial

When, some time back, we talked about the โ€œsisterlyโ€ (to todayโ€™s ASP.Net) PHP way of approaching the C Sorting โ€œinterfaceโ€ to a web application with C Sorting PHP exec Tutorial as shown below, it was inferred that we might approach this, in ASP.Net (using Microsoftโ€™s Visual Studio IDE under Windows), by using a โ€œnew Process()โ€ technique โ€ฆ well, please scratch that idea โ€ฆ Windows security has come down pretty hard on such thoughts โ€ฆ so what we did today was compartmentalize more and allow the โ€œC Sortingโ€ be handled by Windows desktop techniques and has as the โ€œinterface methodโ€ the existance, or not, of files โ€ฆ a favourite technique for us, as much as anything because โ€œmethodologiesโ€ containing โ€œfile_existsโ€ (or its like) are common in so many โ€œserverโ€ programming languages โ€ฆ โ€œserverโ€ not โ€œclientโ€ โ€ฆ so not Javascript.

So we have โ€ฆ

  1. ASP.Net (C# codebehind) code you could call ShowIsPostBackโšซaspx (or call it something better?!) โ€ฆ and its helper Windows (DOS) Command Line โ€ฆ
  2. Windows (DOS) Command Line batch file you could call askโšซbat (which is designed to keep running, and we show with todayโ€™s slideshow how you can use Windows Task Schedular to set it up to be run (the once) in the background, when you start your computer)

As with using PHP as the server language, the โ€œunchangedโ€ programming C code you could call use_qsortโšซc works in conjunction with ASP.Net server side language today. When we say โ€œunchangedโ€ we did decide to copy the use_qsort.exe somewhere into the computerโ€™s PATH. Why? It means no matter where you are, directory wise, on the command line, the use of โ€œunpathedโ€ โ€œuse_qsort.exeโ€ (or even just โ€œuse_qsortโ€) will start the program you want. This is a common requirement, so letโ€™s go over the steps to achieve this below โ€ฆ

  1. Get to Windows (DOS) Command Line โ€ฆ
  2. Type echo %PATH% โ€ฆ take a note of one of the directories that suits and weโ€™ll call that one โ€œC:\MyDesiredDirectoryOnThePathโ€ below (but you need to subsitute your โ€œrealโ€ one in, for it, below) โ€ฆ
  3. Type in cd [path] commands to get yourself to where use_qsort.exe lives now (and after this) โ€ฆ
  4. Type in copy use_qsort.exe โ€œC:\MyDesiredDirectoryOnThePath\*.*โ€

Of more than somewhat help today was ASP.NET 3.5 Unleashed by Stephen Walther โ€ฆ thanks.

So please compare and contrast the server giants and their software integration with some Windows operating system C.



Previous C Sorting PHP exec Tutorial is shown below.

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 thislink 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 thislink.


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 thislink.


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.


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

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

19 Responses to C Sorting ASP.Net Primer Tutorial

Leave a Reply

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