title: ATP list in C, reading and saving usernames
body: <p>I have a problem writing a code that should read <code>username</code>s and put them in list. Every <code>username</code> should be connected to the number of times it has been entered. The problem occurs when entering the second <code>username</code>, my code places that <code>username</code> in the variable called first (where the first is kept). I guess I've done something wrong with the pointers, but I cannot find what. I am confused, in the end of one while loop the first one is the real first one, and when the program enters while again, variable first changes. How could that be? Please help me.
  Thank you :)</p>
  
  <pre><code>typedef struct _user
  {
      char *name;
      int counter;
      struct _user *next;
  } user;
  
  int main()  {
  char userName [10];     
  int found = 0, go_on = 1;
  user *first = NULL, *temp, *new;
  while (go_on == 1) {
          printf ("Username: ");
          scanf("%s", userName);
      if (first) {                                
           // printf ("The first one in list: %s\n", first-&gt;name); - this prints the name of last username entered 
          for (temp = first; temp; temp = temp-&gt;next) {
                 if (strcmp (temp-&gt;name, userName) == 0) {
                  temp-&gt;counter++;
                  found = 1; }
                 if (found== 1) break;}
          if (!found) {
              new = (user*) malloc (sizeof(user));
              new-&gt;name = userName;
              new-&gt;counter = 1;
              temp = new;
              temp-&gt;next = NULL; } }
      else {                      
              new = (user*) malloc (sizeof(user));
          new-&gt;name = userName;
          new-&gt;counter = 1;
          first = new;
          first-&gt;next = NULL; }
      printf ("Go on? (1/0)");
      scanf("%d", &amp;go_on);
      printf ("Current list: ");
      for (temp=first; temp; temp = temp-&gt;next)   
          printf("%s %d\n", temp-&gt;name, temp-&gt;counter);
      //printf ("The first one in list: %s\n", first-&gt;name); - this prints the correct first
  }
  }
  </code></pre>