Finally, I understand that main (INT argc, char * argv []) is a magic horse.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.