EvilZone

Programming and Scripting => C - C++ => Topic started by: kenjoe41 on August 12, 2013, 05:52:10 PM

Title: [c++]Another whats wrong with this code?
Post by: kenjoe41 on August 12, 2013, 05:52:10 PM
Ok, am convinced there is nothing wrong with this code. But i wonder why it won't compile in code::blocks or g++.
Here is the code:
Code: (c++) [Select]
// This program prints its environment variables.
 #include <iostream>
 using namespace std;

 int main(int argc, char** argv)
 {
    extern char **environ; // Needed to access the environment

    int k = 0;
    while(environ[k] != 0) // Is it last C-string in environment?
    {
        // Print the string
        cout << environ[k] << "\n";
        k++;
    }
 return 0;
  }
Title: Re: [c++]Another whats wrong with this code?
Post by: xC on August 12, 2013, 06:12:25 PM
Never used environ(). I looked at the documentation of it though and it looks like you just forgot to include the stdlib.h header.
Title: Re: [c++]Another whats wrong with this code?
Post by: kenjoe41 on August 12, 2013, 06:17:48 PM
Ok, that just did the magic. i will remember next time to consider the documentation.