title: Segmentation Fault 11 in C File I/O
body: <p>I'm writing a function which searches a text file formatted like this:</p>
  
  <p><em>#User1\pass\</em><br>
  <em>#User2\pass\</em><br>
  <em>#User3\pass\</em></p>
  
  <p>I have written the function Check_User:</p>
  
  <pre><code>int Check_User(char input[20], FILE *userlist)
  {
      int c, i;
      fseek(userlist, 0, SEEK_SET);
      while(1)
      {
          while((c = fgetc(userlist)) != '#')
          {
              if(c == EOF)
                  return 1;
          }
          while(input[i] == (c = fgetc(userlist)))
          {
              i++;
          }
          i = 0;
          if(c == '\\')
              return 0;
      }
  }
  </code></pre>
  
  <p>Which is called from here:</p>
  
  <pre><code>while(Check_User(username, userlist) == 0)
  {
      printf("Username already in use. Please select another:");
      Get_Input(username);
  }
  </code></pre>
  
  <p>Check user checks the file pointed to by *userlist to see if the username[20] contains a username which is already in use.  If it is already in use it calls Get_Input for a new username.  </p>
  
  <p>The program makes it all the way to the while loop and then gives me a segmentation fault: 11.  I have read that this often stems from trying to write beyond the end of an array, or generally doing things to memory you don't have access to.  Userlist.txt has been opened in r+ mode.</p>
  
  <p>Thanks for the help.</p>