Paste Search Dynamic
Untitled
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *changePassword() {
  6.   char newPass[30];
  7.   char confirmNewPass[30];
  8.   int compare;
  9.   printf("\nNew password: ");
  10.   scanf("%s", newPass);
  11.  
  12.   printf("\nConfirm new password: ");
  13.   scanf("%s", confirmNewPass);
  14.   compare = strcmp(newPass, confirmNewPass);
  15.  
  16.   if (compare != 0) {
  17.     printf("They dont match :*. Try again!");
  18.     changePassword();
  19.   }
  20.   return newPass;
  21. }
  22.  
  23. int main() {
  24.   char password[30] = "Pass";
  25.   char userInput[30];
  26.   char * newPass;
  27.   int result;
  28.   printf("Password: ");
  29.   scanf("%s", userInput);
  30.  
  31.   result = strcmp(password, userInput);
  32.  
  33.   if (result == 0) {
  34.     printf("\nPassword entered correctly ! :)\n\n");
  35.   } else {
  36.     printf("\nPassword entered incorrectly. Try again :(\n");
  37.     main();
  38.   }
  39.  
  40.   printf("Select an action to proceede. \n[1] Change password \n[2] Exit.\n");
  41.   result = 0;
  42.   scanf("%i", &result);
  43.  
  44.   switch (result) {
  45.   case 1:
  46.     // Pass change functions will go here
  47.     newPass = changePassword();
  48.     printf("%s", newPass);
  49.     break;
  50.   case 2:
  51.     exit(0);
  52.     break;
  53.   default:
  54.     printf("Error, Error, Fallback enabled, returning to main.");
  55.     main();
  56.     break;
  57.   }
  58.  
  59.   return 0;
  60. }
Parsed in 0.008 seconds