Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C] Env. Variables
05-27-2010, 09:24 AM (This post was last modified: 05-27-2010 01:02 PM by Back_track.)
Post: #1
[C] Env. Variables
Code:
/**
*Access to Enviornment Variables - C - *nix
*Author: Back_Track
*May 26, 2010
**/

#include <stdio.h>

/**
*The enviornment variable is the
*third variable (parameter) in the main
*function, it is a char array(String)
*/
int main(int argc,char *argv[], char *env[])
    {
        int i=0; /*our temporary cariable for our while loop*/
        while(env[i])/*While there is still an enviornment variable DO*/
        {
            printf("Enviornment variable #%d is %s\n",i,env[i]);
            /*
            *You want to increment the temp. var after the enviornment variable
            *has been accessed and printed to the terminal.
            */
            i++;
        }
        
        return 0;
    }

Oh, did i tell you? I'm also learning C with Java Big Grin

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
05-28-2010, 03:34 AM
Post: #2
RE: [C] Env. Variables
Yeah very good example. If you write main() function in that way, you can manipulate with certain data attached to program .

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
01-06-2011, 03:02 PM
Post: #3
RE: [C] Env. Variables
Note that it's not guaranteed to work, since this depends on implementation.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: