1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <stdio.h>
#include <string.h>
#define PASSWORD_MAXLEN 32
void fclean(char *buff, FILE * fp);
int main(void)
{
char const *my_secret_pw = "developpez";
char word[PASSWORD_MAXLEN + 1] = "";
printf("Enter your password : ");
/* -tc- force l'affichage de l'invite */
fflush(stdout);
if (fgets(word, sizeof word, stdin) != NULL)
{
fclean(word, stdin);
if (strcmp(word, my_secret_pw) == 0)
{
printf("Password OK\n");
}
else
{
printf("Password KO\n");
}
}
/* -tc- l'appel a getchar() n'est pas necessaire */
return 0;
} |
Partager