Question: Please write the code in C language. Program Description: This program will be written in the C language, and will demonstrate accessing the Unix command

Please write the code in C language.

Please write the code in C language. Program Description: This program will

be written in the C language, and will demonstrate accessing the Unix

Program Description: This program will be written in the C language, and will demonstrate accessing the Unix command line, as well as working with strings and pointers in C. The command line is stored as an array of strings. Each element in the array is a null- terminated array of characters. The array itself is terminated with a NULL pointer, although you can learn the length of the array from the array length which is also passed in. There are two arguments passed into main which are of interest to us. The first is the argument count (args) which tells us how many non-null elements are in the argument array (or argument vector). The second argument is the array of command-line arguments (argy) which is an array of character pointers (strings) where each non-null pointer contains the address in memory of a string containing one command line argument. This argy array is itself terminated by a NULL pointer (a pointer containing address 0x00000000, which is not a legal address on the system). You can determine the number of command line arguments either from argc, or by iterating over the argy array until that NULL pointer is seen. For this assignment I want you to iterate until the NULL pointer is seen. Main may therefor be declared as: int main(int argc, char **argy) The following diagram shows the argy array corresponding to the following command-line: Ja.out one two three Note how each element in argy points to contains the address of) the corresponding argument. The first element in the array (argy[0]) points to a string with contents"./a.out". This string is terminated with a null byte (different from a NULL pointer). A null byte is a byte with value 0, also shown as the escaped character '\0'. The next element (argy[1]) points to "one", then argy[2] points to "two", and finally argy[3] points to the string "three". The last element in argy (argy[4] is NULL, and does not point to anything. There are no arguments after three". Thus there are 4 non-null pointers in the argy array (argy[O] through argy[3]) and the argc counter is therefore equal to 4. argy NULL le 110 # Id 110 'n le 10 / a 11 Each non-NULL element in the argy array therefore represents a separate command line argument. You will print each of these out, along with the position in the argy array. For example: argy[0] = "./a.out" argy[1] = "one" argy[2] = "two" argy[3] = "three" argy[4] = NULL Assignment Objective: Display the contents of any command line which a user might enter. This means that you cannot make any assumptions about the length of the command line, or its contents. Just print what you find. Be sure to enclose each argument in double-quotes, so that any spaces which might find there way into an argument are shown. Requirements: Your solution must be written using the C language. It must compile and run on the CSE machines. You should include your name (under which you registered) in a comment at the top This is an individual programming assignment that must be the sole work of the individual student. Any instance of academic dishonesty will result in a grade of "F" for the course, along with a report filed with the Academic Integrity Database. Sumission: You will electronically submit this file into the appropriate assignment on Canvas by the due date and time

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!