fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. char password[] = "1223";
  6. char input[50];
  7. int attempts = 0;
  8. int authenticated = 0;
  9.  
  10. while (attempts < 3) {
  11. printf("Enter password: ");
  12. scanf("%s", input);
  13.  
  14. if (strcmp(input, password) == 0) {
  15. printf("Access granted\n");
  16. authenticated = 1;
  17. break;
  18. } else {
  19. attempts++;
  20. if (attempts < 3) {
  21. printf("Wrong Password\n");
  22. }
  23. }
  24. }
  25.  
  26. if (!authenticated) {
  27. printf("Wrong Password. You are an imposter\n");
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter password: Wrong Password
Enter password: Wrong Password
Enter password: Wrong Password. You are an imposter