title: Create a Simple Registration and Login System with C
body: <p>After some help if possible.</p>
  
  <p>I have a class project that requires building a simple login and registration system, which also needs input validation for the password and username meeting length/character requirements. 
  I am an absolute beginner and really struggling. I haven't even got around to making the validation as the code I have so far can't compile. I understand it might look messy, but I do struggle with c programming.</p>
  
  <p>Here is the error</p>
  
  <pre><code>login2.c: In function ‘login’:
  login2.c:11:15: error: storage size of ‘l’ isn’t known
     11 |  struct login l;
  </code></pre>
  
  <p>Any help would be absolutely amazing. 
  Thanks in advance!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  login()
  {
      char username[30],password[20];
      FILE *log;
      log=fopen("login.txt","r");
      struct login l;
  
      printf("\nPlease Enter your login credentials below\n\n");
      printf("Username:  ");
      fgets(username, 30, stdin);
      printf("\nPassword: ");
      printf("\n");
      fgets(password, 20, stdin);
  
      while(fread(&amp;l,sizeof(l),1,log))
          {
          if(strcmp(username,l.username)==0 &amp;&amp; strcmp(password,l.password)==0)
  
              {   
                  printf("\nSuccessful Login\n");
              }
          else 
              {
                  printf("\nIncorrect Login Details\nPlease enter the correct credentials\n");
              }
  }
  
  fclose(log);
  
  }
  
  struct login
  {
      char fname[30];
      char lname[30];
      char username[30];
      char password[20];
  }
  
  
  registration()
  {
      char firstname[15];
      FILE *log;
      log=fopen("login.txt","w");
      struct login l;
  
      printf("\nWelcome to your online course provider. We need to enter some details for registration.\n\n");
      printf("\nEnter First Name:\n");
      scanf("%c",l.fname);
      printf("\nEnter Surname:\n");
      scanf("%c",l.lname);
  
      printf("Thank you.\nNow please choose a username and password as credentials for system login.\nEnsure the username is no more than 30 characters long.\nEnsure your password is at least 8 characters long and contains lowercase, uppercase, numerical and special character values.\n"); 
  
      printf("\nEnter Username:\n");
      scanf("%c",l.username);
      printf("\nEnter Password:\n");
      scanf("%c",l.password);
  
  
      fwrite(&amp;l,sizeof(l),1,log);
      fclose(log);
  
      printf("\nConfirming details...\n...\nWelcome, %c!\n\n",firstname);
      printf("\nRegistration Successful!\n");
      printf("Press any key to continue...");
          getchar();
      system("CLS");
      login();
  }
  
  
  int main()
  {
      int option;
  
      printf("Press '1' to Register\nPress '2' to Login\n\n");
      scanf("%d",&amp;option);
  
      if(option == 1)
          {
              system("CLS");
              registration();
          }
  
      else if(option == 2)
          {
              system("CLS");
              login();
          }
  }
  </code></pre>