Common cross-platform Ides how to add parameters to the main function and execute correctly

Source: Internet
Author: User

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:

 

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.