Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to pass more than 1 argument in main method in c

VB
INT main(int argc, char *argv[])
{

    // to avoid compiler warning


    printf("\n\n\n\n");
    printf("-----------------------TEST IFD-----------------------------\n\n");

    if (argc>1)
    {
//coding
}
Now it takes 1 argument i.e. 'c' when i complile in vs 2008
Posted
Comments
Richard MacCutchan 8-Dec-11 5:47am    
What is the compiler warning and on which line?

all arguments what ever you pass will be stored as a vector of strings to the main.
Suppose your program name is Test.exe
You write
Test.exe A B C
in command line.
So your main program gets the following parameter

C++
argv[0] = "test.exe" //This is always your program name
argv[1] = "A"
argv[2] = "B"
argv[3] = "C"



now the value of argc (Argument Count) is the total number of elements in the char** argv(Argument Vector). In the above case it is argc=4
 
Share this answer
 
insert the argument in debug in command argument in property of project.
like in command argument aaa
it is a parameter and argv[1] will be aaa
 
Share this answer
 
v3
Comments
Albert Holguin 8-Dec-11 8:55am    
This isn't exactly what you asked...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900