WHATNEXT.C - The Batch File Interrogator

This is an example of how to read the data on the command line following the function call. Notice that there are two variables listed within the parentheses following the main() call. The first variable is a count of words in the entire command line including the command itself and the second variable is a pointer to an array of pointers defining the actual words on the command line.

First the question on the command line, made up of some number of words, is displayed on the monitor and the program waits for the operator to hit a key. If the key hit is one of those in the last ``word'' of the group of words on the command line, the number of the character within the group is returned to the program where it can be tested with the ``errorlevel'' command in the batch file. You could use this technique to create a variable AUTOEXEC.BAT file or any other batch file can use this for a many way branch. Compile and run this file with TEST.BAT for an example of how it works in practice. You may find this technique useful in one of your batch files and you will almost certainly need to read in the command line parameters someday.

An interesting alternative would be for you to write a program named ``WOULD.C'' that would return a 1 if a Y or y were typed and a zero if any other key were hit. Then your batch file could have a line such as;


WOULD YOU LIKE TO USE THE ALTERNATIVE METHOD (Y/N)


Dos would use ``WOULD'' as the program name, ignore the rest of the statement except for displaying it on the screen. You would then respond to the question on the monitor with a single keyhit. Your batch file would then respond to the 1 or 0 returned and either run the alternative part of the batch file or the primary part whatever each part was.

	WOULD YOU LIKE PRIMARY (Y/N)
	IF ERRORLEVEL 1 GOTO PRIMARY
	(secondary commands)
	GOTO DONE
	:PRIMARY
	(primary commands)
	:DONE