In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use the main function. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Main function is the program entry point of C-based development platform. In general, we seldom pay attention to the function main function parameter list, but simply give the following situation.
Int main () {system ("pause"); return 0;}
Open MSDN and view the main function
Main (int argc, char * argv [], char * envp [])
{
Program-statements
}
First of all, let's look at the first two parameters, argc and argv [], which are mainly used to describe command-line parameters, but they cannot be said to be command-line arguments. For a program, they represent the formal parameters of the main function. (a little twists and turns)
For example, open cmd, as shown below
We enter hello.exe, which means that this is an executable program, and then we can keep up with some parameters, such as-mMagne2, etc., parameters have no practical significance here, but if we write hello.exe in advance, and then the parameters we add can be obtained, then the parameters we add here are the so-called command line parameters, and the parameters of the main function are two different things.
That can be run under cmd, how to set environment variables in the external environment?
Open the VS compiler, Project-> Properties-> Debug
Here, we can set the command line parameters in advance.
Argc and argc [] are used to adjust these parameters, and they can get the command line parameters we set.
Among them, argc represents the number of parameters, for programs, to identify command-line parameters, is as a string to identify, and argv [] is an array of character pointers, each element of the array is of type char*, pointing to the parameters of our command-line parameters, the array is named argv.
Again, in the above example, we have an argc value of 4, while there are five elements of type char* in argv [], namely "hello.exe", "- m", "2", "1", and finally a NULL. The number of parameters before NULL in argc.
Then we can access the contents of our command line arguments through array subscript argv [I], and then implement our function. Usually, the argc will be judged at the beginning of the program to determine whether it meets the number of parameters we want to access next. If it is less than the minimum number of parameters we need, the program will often collapse.
Another point that needs to be emphasized is that these parameters are just parameters, the name is not fixed, we can change it, but we usually understand it this way.
Obviously, every time we need to implement an operation, we need to go to the project-> attribute to change the command-line arguments, which is not what we want, but the command-line parameters are really important, mainly in the cmd environment.
Find the project we just built in the cmd environment, find the executable program (suffix .exe) under Debug, follow it with our parameters, click enter, the parameters will be obtained, and the results we want will appear.
To take another simple example, fcopy.exe is an executable program file that implements file replication, running the fcopy format on the command line:
System prompt + fcopy.exe in.dat out.dat
In.dat "and" out.dat "are command line arguments, where" in.dat "and" out.dat "can be preceded by a drive letter and a lookup path.
About environmental variables
To put it simply, "Path" is a variable that stores the directory path where some common commands are stored. Similar to the default path of DOS, when the bar directory is added to the Path, some programs will not only look in the current folder, but also look in the default path.
For example, path tells the system that when the system is asked to run a program without telling it the full path where the program is located, the system should not only look for the program under the current directory, but also look under which directories.
In general, do not see the significance of environment variables, but those who have studied Java should know that eclipse installation is to configure environment variables, that is, to copy the bin directory to the past, the specific reason, here is not much explanation. Another big problem that environmental variables can solve is the problem of software sharing between two systems. For example, win7 and xp systems are installed on disk C and disk D respectively, but some software is only installed under one system and often cannot be used under another system. The more troublesome way is to install it again under another platform.
Why does the software installed under one system not open in another system? The reason is that when installing software, it is often necessary to copy some files to the system directory, and when using another system, it will not be able to run because of the lack of these files. Environment variables can solve this problem very well.
To view the environment variables, you can set the environment variables of the system through my computer-> Properties-> Advanced, but does the environment variable set here have a corresponding entry in the registry? The answer is yes.
Thank you for reading! This is the end of the article on "how to use the main function". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.