CMPS-3600 - Spring 2023 - Semester Project - Challenge
Challenge 1
Count the number of command-line arguments.
-------------------------------------------
1. At the top of your main function, put this line of code.
argc = get_argument_count(argv);
2. Now you write the get_argument_count function body.
Discussion:
argv is an array of addresses.
Each address is one command-line argument.
An address of 0 or NULL is a sentinel that terminates the array.
Use this knowledge to step through the array and count the arguments.
The function needs only 4-lines of code.
Pseudo-code for the function body...
DECLARE INTEGER i
SET i to 0
WHILE argv[i] IS NOT NULL DO
INCREMENT i
END WHILE
RETURN i
Knowing how to write this function without the [] operator can earn you
some extra credit.
Challenge 2
Cause the window to close by itself, after looping a given number of times.
---------------------------------------------------------------------------
1. Check the first command-line argument after the program name.
2. Convert it to an integer using atoi() function.
If there is no argument, your number is 0.
3. The number is how many times your main-function event-loop will loop.
4. The window will then close itself.
Discussion:
Leave the usleep(4000); in your main loop.
Your new code should be placed just after the usleep.
A 0 or negative argument value should be ignored.
In this case, take no action in the main loop.
A change to variable 'done' should be used to end the program.
Pseudo-code for the functionality...
(before the main loop)
DECLARE INTEGER n
SET n to COMMAND LINE ARGUMENT #2
(inside the main loop)
IF n IS GREATER THAN 0 THEN
DECREMENT n
IF n EQUALS 0 THEN
SET done TO 1
ENDIF
ENDIF