title: C in Linux - using execle() to output an environment variable?
body: <p><strong>Program 1</strong>          </p>
  
  <p>In program 1 I have attempted to create the sole environment variable envar putting it in the env array which is passed to the execle function for the environments creation which program 2 will be run in.                                                  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char *argv[]){
  
  int ret;
  char envar[] = "Big ol' environment variable ;D"; 
  char *env[2] = {envar, 0};
  
  ret = execle("./exec_test1.1", "exec_test1.1", 0, env);
  
  printf("my prog failed ret = %d", ret);
  
  return 0;
  }
  </code></pre>
  
  <p><strong>Program 2</strong></p>
  
  <p>I intended this code in the same directory to retrieve the environment variable envar on execution and to print it. However I the output in its place is null "memes and dis (null)" I have searched but can't see my mistake. Program two is almost identical to another I found for the same purpose so I assume my mistake is in program one.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char *argv[]){
  
  char *envptr = getenv("envar");
  
  printf("memes and dis %s\n", envptr);
  
  return 0;
  
  }
  </code></pre>
  
  <p>Thanks</p>