Please write the program in C as explained below:
Here is the code for sortMain.c that needs to be modified based on the requirements above:
#include #include #include "mysort.h" int main(int argc, char * argv[]) { int data[100000]; /* Array of ints to sort */ int nDataItems; /* number of actual items in the array */ int i; /* Test data */ nDataItems = 4; data[0] = 10; data[1] = 20; data[2] = 30; data[3] = 40; mySort(data, nDataItems); /* Check that the data array is sorted. */ for(i = 0; i data[i+1]) { fprintf(stderr, "Sort error: data[%d] (= %d)" " should be Here is the code for cmdlineArgsDemo.c that you can copy and paste:
#include #include int main(int argc, char * argv[]) { int i; fprintf(stderr, "I was invoked with the command: %s ", argv[0]); if (argc > 1) { fprintf(stderr, "The command line arguments are: "); for(i = 1; i
Note: Please include screenshots of the output and command lines as shown above.
Tutorial II: Command line arguments In this tutorial you will learn how to obtain and use and command line arguments that were entered by the user when a command is invoked. We now examine how the parameters arge and argy that are passed to the main function can be used. Consider the following standalone program (that is furnished to you in the file cmdlineArgsDemo.c): #include #include int main(int arge, char * argv[]) int i; fprintf(stderr, "I was invoked with the command: ts ", argv[0]); if (arge > 1) fprintf(stderr, "The command line arguments are: "); for (i = 1; i } else fprintf(stderr, "There were no command line arguments. "); 1 exit(0); Create an executable from this source code file with the command: gce - cmdlineDemo cmdlineArgsDemo.c Invoke the command with: cmdiline Demo The output should be: I was invoked with the command: cmdline Demo There were no command line arguments. Now try the command: emdlineDemo hello 125 22 -6 The output should be: I was invoked with the command: cmdline Demo The command line arguments are: argv[1] (as string): hello (as int): 0 (as int in hex): 0 argv[2] (as string): 125 (as int): 125 (as int in hex): 70 argv[3] (as string): 22 (as int): 22 (as int in hex): 16 argv[4] (as string): -6 (as int): -6 (as int in hex): FFFFFFFA Requirement 2: Use arge and argv in main function Copy your sortMain.c to sortMain2.c. Modify the new file so that the command works as follows: If no command line arguments are given, sort the hardcoded test data as before. If there are command line arguments, convert them to integers and use them values to initialize the data array to be sorted