#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    101
    Rep Power
    0

    Environment variables (with a quick question)


    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    	putenv("BANANA=yellow");
    	printf("%s",getenv("BANANA"));
    	getchar();
    	return 0;
    }
    Can someone please explain more into detail where the environment variable, BANANA, goes? My book says an environment variable is just a variable that's "an array of strings." and although that may be right I want to know where these variables go. Do they head with the other environment variables are like PATH and CD?

    Also, my quick question is this - I found a site that stores the c programming language book but it's only the second edition. I couldn't find the first edition I was able to download for free or find it on a .PDF website. Am I able to just read the second edition to be able to understand or do I have to read the 1st edition before the second?
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Environment variables go into the program's environment. Every program has an environment. Every program's execution starts by inheriting the environment of its parent process. From there, every program is free to changing its own environment which will be copied over to any processes that that program itself spawns.

    Environments are handled by the operating system. You do not need to know exactly where they are kept nor the details of how the operating system handles them. You only need to know how to work with them and to understand how they affect your program's execution.

    Also, my quick question is this - I found a site that stores the c programming language book but it's only the second edition. I couldn't find the first edition I was able to download for free or find it on a .PDF website. Am I able to just read the second edition to be able to understand or do I have to read the 1st edition before the second?
    Are you talking about Kernighan and Ritchie's (AKA "K&R") The C Programming Language?

    No, you don't need to have read the first edition. In fact, reading the first edition at this stage would be detrimental to your education -- reading it later would only be for historical reasons or for understanding older non-standard programs still to be found on the Internet. C went through some major changes, good changes, with the 1989 ANSI standard. Part of what seems to be confusing new readers is that in their second edition K&R were also trying to inform experienced C programmers about those changes. Indeed, there's an entire appendix devoted to those changes.

    Another reason why it's worthless to try to learn K&R C (ie, C in the first edition) is that no current compiler supports K&R C anymore. Turbo C does have an option to support K&R, but then it's not a current compiler.

IMN logo majestic logo threadwatch logo seochat tools logo