Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Command line argument

    • 0
    • 4
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 334
    Comment on it

    Command Line Argument

    1. Command line argument is a way of supplying parameter to the program whenever it is invoked. In command line argument when user call main method it is called by two arguments.The first is the number of command-line argument. The second is a pointer to an array of character string that contain the argument, one per string. which echoes its command-line arguments on a single line, separated by blank space. i.e echo hello, family prints the output hello, family

    Source Code for command lline argument

    #include
    
     int main( int argument, char *argument1[] ) 
         {
       if( argument == 2) 
             {
          printf("The arguments you have supplied is %s\n", argument1[1]);
             }
       else if( argument> 2 )
            {
              printf("many arguments supplied.\n");
            }
       else 
                 {
              printf("Atleast one argument expected here.\n");
                 }
        }
    
    output:-
    when you compile code like this:
     ./out shristi
    
    The argument you have supplied is shristi
    
     ./out shristi nawani
    
    Many arguments supplied.
    
      ./out
    
    Atleast One argument expected here.
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: