title: c file input function not working as intended
body: <p>I have this function that is supposed to check if a username is blacklisted and if it isn't, it's supposed to "log in" the user by checking if that username is present in a second file. If it is, then that line from the file will be remembered and the function should check in a third file if the password on the remembered line is correct, so basically the line of the username is the line of his password and if those two match with the input and the user isn't blacklisted then it should return a postive answer.</p>
  
  <p>Unfortuntely my function seem to be returning a positive answer no matter what I type. Can anyone point out what my mistake is so that it will work as intended ?</p>
  
  <p>Edited out unintentional mistakes, I still have and issue where I can not stop reading if the file isn't in blacklist.txt</p>
  
  <p>code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;ctype.h&gt;          
  #include &lt;arpa/inet.h&gt;
  #include &lt;netdb.h&gt;   
  
  int login(char username[20],char pw[20])
  {
      FILE *fp = fopen("blacklist.txt","r");          
      int ok = 0, pw_line=0,oku=0,savepwline=0,count=0,okp=0;
  
      while (ok==0)                                            
      {
          if (fp != NULL)
          {
              char line[20];
              while (fgets(line,sizeof(line), fp) != NULL)
              {                           
                  size_t i=strlen(line)-1;
                  if(line[i]=='\n')
                  line[i]='\0';
                  if (strcmp(username,line) == 0 ) ok=1;
              }
          }
      }
      fclose(fp);
      if (ok==1)
      {
          printf("user blacklisted\n");
      }
      else
      {
          FILE *fp2 = fopen("loginuser.txt","r"); 
          while (oku==0)                                            
          {
          if (fp2 != NULL)
          {
              char line3[20];
              while (fgets(line3,sizeof(line3), fp2) != NULL)
              {
                  pw_line++;                            
                  size_t i=strlen(line3)-1;
                  if(line3[i]=='\n')
                  line[i]='\0';
                  if (strcmp(username,line3) == 0 ) { oku=1; savepwline=pw_line; }
              }
          }
          }
          FILE *fp3 = fopen("loginpw.txt","r"); 
          if (oku==1)
          if (fp3 != NULL)
          {
              char line2[20];
              while (fgets(line2,sizeof(line2), fp3) != NULL)
              {
                  if ( count == savepwline )           
                  {
                      size_t i=strlen(line2)-1;
                      if(line2[i]=='\n')
                          line2[i]='\0';
                      if (strcmp(pw,line2) == 0 ) okp=1;
                  }
                  else count++;
              }
          }
      fclose(fp2);
      fclose(fp3);
      }
      if(oku&amp;&amp;okp) return 1;
      else return 0;
  }
  
  int main()
  {
   char a[20],b[20];
   scanf("%s",a);
   scanf("%s",b);
   if(login(a,b)) printf("yes");
  else printf("no");
  }
  </code></pre>
  
  <p>sample file ("loginuser.txt"/"loginpw.txt") :</p>
  
  <pre><code>hihi
  aloss
  foif
  distsd
  </code></pre>
  
  <p>blacklist.txt:</p>
  
  <pre><code>carl
  gigc
  ffgfd
  gdfgdd
  rreti
  </code></pre>