Author Topic: [c++]Another whats wrong with this code?  (Read 868 times)

0 Members and 1 Guest are viewing this topic.

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
[c++]Another whats wrong with this code?
« 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;
  }
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

xC

  • Guest
Re: [c++]Another whats wrong with this code?
« Reply #1 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.
« Last Edit: August 12, 2013, 06:12:42 pm by xC »

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: [c++]Another whats wrong with this code?
« Reply #2 on: August 12, 2013, 06:17:48 pm »
Ok, that just did the magic. i will remember next time to consider the documentation.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]