1. ECLIPSE-CDT How to add main function parameters:
Open Eclipse, create a new project, create a new source file, for example in C, write code like this:
#include <stdio.h>//int argc: The command line has several strings//Char *argv[] means: A character pointer array, each element is a pointer, each pointer stores a string header addressintMainintargcChar*argv[]) {printf ("%d\n", ARGC);//number of printing parameters for(inti =0; i < argc; i++) printf ("%s\n", Argv[i]);//Argv[i] is a character pointer that stores a string header address return 0;}
After writing such as:
Click Compile:
Compile successfully, and then run the program as follows:
At this point the main function in the program has only one parameter, and prints it out, followed by additional parameters:
Right-click Project-->run as-->run configrations-->arguments--> write the parameters that you want to add, which can be separated by a space and separated by line breaks
Then click Apply, then click Run.
After the successful run, you can see the following results, successfully printed out!
2. How Visio studio adds the main function parameter:
Open vs 2015, create a new project, create a new source file, here in C for example, write the code as follows:
#include <stdio.h>#include<stdlib.h>//int argc: The command line has several strings//Char *argv[] means: A character pointer array, each element is a pointer, each pointer stores a string header addressvoidMainintargcChar*argv[]) {printf ("%d\n", ARGC);//number of printing parameters for(inti =0; i < argc; i++) printf ("%s\n", Argv[i]);//Argv[i] is a character pointer that stores a string header addressSystem ("Pause");}
After writing such as:
Compile and run:
At this point the main function in the program has only one parameter, and prints it out, followed by additional parameters:
Right----Properties----debug----write the parameter you want to add, separated by a space
Then click "OK" to run again.
The results of the operation are as follows:
3. Codeblocks How to add main function parameters:
Open Codeblocks, create a new project, create a new source file, here in C for example, write the code as follows:
#include <stdio.h>//int argc: The command line has several strings//Char *argv[] means: A character pointer array, each element is a pointer, each pointer stores a string header addressintMainintargcChar*argv[]) {printf ("%d\n", ARGC);//number of printing parameters for(inti =0; i < argc; i++) printf ("%s\n", Argv[i]);//Argv[i] is a character pointer that stores a string header address return 0;}
After writing such as:
Compile and run:
At this point the main function in the program has only one parameter, and prints it out, followed by additional parameters:
Project-->setprograms ' arguments-->debug--> writes the parameters that you want to add, which can be separated by a space or separated by line breaks
then click OK.
Compile and run again: