Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. FILE *fp;
  5. char username[30];
  6. char password[30];
  7. char password2[30];
  8.  
  9. void enterpw() {
  10.        
  11.         printf ("\nPassword: ");
  12.         fgets (password, sizeof(password), stdin);
  13.  
  14.         printf ("Confirm password: ");
  15.         fgets (password2, sizeof(password2), stdin);
  16.  
  17.         while (strcmp(password, password2)) {
  18.                 printf ("\nError: Passwords do not match. Try again.\n");
  19.                 enterpw();
  20.         }
  21.  
  22. }
  23.  
  24. int main() {
  25.        
  26.         printf ("\nPlease enter your username: ");
  27.         fgets (username, sizeof(username), stdin);
  28.        
  29.         enterpw();
  30.  
  31.         fp = fopen ("user.dat", "a");
  32.         fprintf (fp, "%s%s\n", username, password);
  33.         fclose (fp);
  34.        
  35.         printf("\nPasswords match. Data written to file.\n\n");
  36.         return 0;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement