title: Why is my variable corrupt after returning from a function?
body: <p>Below is my c code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  
  char *username;
  char *password;
  
  void set_credentials(char*, char*);
  
  int main(void)
  {
    set_credentials();
    printf("%s\n", username);     //look here 3
    printf("%s\n", password);     //look here 4
    return EXIT_SUCCESS;
  }
  
  void set_credentials(char *username, char *password)
  {
    char c;
    char lines[2][100];
    char * tmp = * lines;
    char * user = "user";
    int i = 0;
    FILE *fp = fopen("/netnfork/config/netnfork_credentials.properties", "r");
  
    if (fp == NULL)
      exit(EIO);
    while ((c = fgetc(fp)) != EOF)
    {
      if (c != '\n')
      {
        *tmp = c;
        tmp++;
      } else {
        *tmp = '\0';
        i++;
        tmp = lines[i];
      }
    }
    fclose(fp);
    i = 0;
    while (i &lt; 2)
    {
      if (strncmp(user, lines[i], 4) == 0)
      {
        username = lines[i] + 5;
        printf("%s\n", username); //look here 1
      } else {
        password = lines[i] + 9;
        printf("%s\n", password);  //look here 2
      }
      i++;
    }
  }
  </code></pre>
  
  <p>Now, when I run the code, I get this:</p>
  
  <blockquote>
    <p>myname //for 1<br>
    mypassword //for 2<br>
    myname // for 3<br>
    mypasswo��� // for 4  </p>
  </blockquote>
  
  <p>I can't understand why that behavior. Have anyone ideea about why that?</p>