Tag: Main Parameter DoS
Previously, we saw that all main (INT argc, char * argv []) programs need to enter commands in the doscommand status, and do not know how to open dos, so we have never tried, I met another one today, so I decided to study it.
First, write my program. My program is vs2008. The procedure is as follows:
# Include <stdio. h> void main (INT argc, char * argv []) {While (argc> 1) {++ argv; printf ("% s \ n", * argv ); -- argc ;}}
In fact, this is a simple small program in the textbook. After running, it enters the DOS interface.
Then how does one enter the DOS interface? There are two methods: 1. Output CMD in the Start search and click to enter. 2. Press the Windows key and the r key, and Enter cmd in the open window to open it. Enter the default DoS work environment in our user folder. To return to drive C, enter CD... and press Enter. If you want to access another disk (add disk D), enter D.
Enter the executable file of the program in dos(find the. exe file under the debug folder for a long time). Another quick way is to drag the file directly to the DOS interface, just like uploading the file via QQ.
After the file path is completed, enter "Space Beijing Space Shanghai press ENTER" (filename Beijing Shanghai) to view the running results of the program. In fact, Beijing and Shanghai are output.
How does the program run? When you enter the executable file name of the main function in the Command state, the operating system calls the main function. The input content is passed to the main parameter. Number of argc records. argv [] is a pointer array that records the input address. If we input the file path, Beijing, and Shanghai, argv is 3, argv [0], argv [1], in argv [2], the first address of the input three contents is stored.