Correction lecture.c

This commit is contained in:
HORVILLE 2021-10-25 16:38:03 +02:00
parent 21bc32cdd7
commit 307a131abe

View File

@ -6,16 +6,25 @@ int main(int argc, char * argv[]) {
char real_password[] = "test 1212 34";
char password[27];
for (int i = 1; i < argc; i++) {
if (i != 1) strcat(password, " ");
if (strlen(password) + strlen(argv[i]) > 26) {
puts("Mot de passe trop long !");
printf("Veuillez entrer votre mot de passe : ");
char c;
for (int i = 0; i < 27; i++) {
if (i < 26) {
c = getchar();
password[i] = c;
if (c == '\n') {
password[i] = '\0';
break;
}
} else if (getchar() != '\n') {
printf("Mot de passe trop long !\n");
return EXIT_FAILURE;
}
strcat(password, argv[i]);
}
if (strcmp(password, real_password)) {
if (strcmp(password, real_password) == 0) {
puts("Authentification réussie.");
} else puts("Mot de passe incorrect.");