Showing posts with label environment variable. Show all posts
Showing posts with label environment variable. Show all posts

Wednesday, 14 May 2014

Command Line Argument

Every C program must have a function called main(), which is the point where execution of the program starts. .When the program is executed, the command line argument are made available via three arguments to the function main(). So the function prototype for the main() function is
                    
              int main(int argc, char *argv[], char *envp[]);

The  Second parameter, *argv[] parameter is an array of  char pointers. The first element in  argv[]
always  points  to  the  program’s  name,  and  each  subsequent member points to a parameter( command-line arguments).
Some compilers and operating systems don’t provide the program name, but have argv[0] point instead to some predefined string constant, such as "C".   Each parameter is separated by the operating system’s default parameter separator, usually a blank or comma. Under the PC’s DOS operating system, only a blank is used as a separator. 

The First parameter, argc parameter, an integer, contains the number of elements in the passed
array of  argv[]. The list of pointers in argvis terminated by a NULL pointer (i.e., argv[argc] is NULL).

The Third argument, *envp[] parameter,is an array of  char pointers or is an array of strings representing the variables set in the user's environment. I give u only small intro in environment variable:

Each process has an associated array of strings called the environment list, or simply the environment. Each of these strings is a definition of the form name=value. Thus, the environment represents a set of name-value pairs that can be used to hold arbitrary information. The names in the list are referred to as environment variables.

A simple program that prints both the passed parameters and the environment strings to the screen. This program’s output depends somewhat on which operating system it runs


#include                // Make includes first part of file
#include              // For string functions.

int main( int argc, char *argv[], char *envp[] )
{
             int i;
             printf("\n");
             printf("Program name is '%s'\n\n",argv[0]);
                                   // argc includes the program name, so decrement for actual passed parameters.
             printf("Number of parameters %d \n\n",argc - 1);
                                  // It's just as valid is to use:
                                 // for (i = 1; i < argc; i++)
             for (i = 1; argv[i]; i++)
             {
                       printf("Passed parameter %2d is '%.50s'\n",i,argv[i]);
              }
              printf("\n");


                              // Environment variables may not be meaningful for all
                              // operating systems. Check the compiler's documentation.
                              // If this information is not available on your system,
                             // delete the below for() loop.
    

             for (i = 0; envp[i]; i++)

             {

                       printf("Environment string %2d is '%.50s'\n",i,envp[i]);

              }

              getchar();

              return (0);

}
Output of this program in my system using cygwin is like this:


Tuesday, 13 May 2014

How to install JDK and configure environment variable

  1.  Download JDK from the Oracle site
  2.  Double click on the downloaded exe file and install it to your system.
  3.  Envirnment variable setting .
  4. Right click on my computer and select properties.

   5. Click on Advanced system setting.


   6. Click on Environment Variables.


   7. Add new user variable with name is path and value is where your jdk's bin directory .


   8. After setting environment variable start command prompt and run javac command if you see
       following output then you have successfully set the environment variable




Monday, 12 May 2014

How To Install Maven

To Install Maven into your local system follow the following steps.

1. Download the Maven Binaries from Apache community site.
2.Unzip the downloaded zip file.
3.Now Update path environment variable.Assign value to path variable till your Maven bin directory.
E.g. D:\apache-maven-3.2.1\bin



4. Add MAVEN_HOME environment variable.Assign value to MAVEN_HOME varialble where your maven is unzipped.
E.g. D:\apache-maven-3.2.1



5. Add JAVA_HOME environment variable.Assign value to JAVA_HOME varialble where your JDK is Installed.
E.g. D:\JDK7.0


6. After setting environment variables start command prompt and run command mnv --version.
If you getting following output the you have successfully installed Maven.