I have this code for a school project. Our teacher just want a simple function which puts stars instead of text for a login menu.
So I wrote that:
void login_menu(){
char nickname[15], password[15] = { '/0' };
int check=0;
while (check != 1){
printf(" your nickname : ");
int checknickname=0;
while(checknickname!=1){
scanf("%s",&nickname);
if(strlen(nickname)>1){
checknickname=1;
}
else{
printf(" your nickname : ");
}
}
int checkpw=0;
printf(" your password : ");
while(checkpw!=1){
int i;
for (i = 0; i < 10;i++) {
password[i] = _getch();
_putch('*');
if (password[i] == 13){
password[i] = '\0';
break;
}
}
if(strlen(password)>1){
checkpw=1;
}
else{
printf(" your password : ");
}
}
printf("\n");
if((strcmp(mdp,"admin")==0) ){
printf("mdp");
}
if( (strcmp(pseudo, "admin")==0 ) && (strcmp(mdp, "admin")==0) ){
system("cls");
check = 1;
user_menu();
}
else{
printf("your logs are incorrect");
}
}
}
Its working fine but I have some warnings :
C:\Users\superneiluj\Desktop\Poly Music 1.0\main.c|434|warning: multi-character character constant [-Wmultichar]|
C:\Users\superneiluj\Desktop\Poly Music 1.0\main.c|434|warning: overflow in implicit constant conversion [-Woverflow]|
for the line
char nickname[15], password[15] = { '/0' };
and
C:\Users\superneiluj\Desktop\Poly Music 1.0\main.c|441|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[15]' [-Wformat=]|
for the line
scanf("%s",&nickname);