There are quite a lot of mistakes in your program (still!). So instead of pointing out each and every of them, I just whipped up my own code and have offered explanations through comments.
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
char *loginID[] = {"user1", "user2", "user3"};
char *passwords[] = {"pass1", "pass2", "pass3"};
char login[6];
char pass[6], temp;
int i, loginNumber;
printf("Enter the login id\n");
fgets(login,6,stdin); // Use fgets instead of gets or scanf(%s)
for(i=0; i < 3; i++) // Need to see if the entered login ID is any one of the three login IDs
{
if(!strcmpi(loginID[i],login)) //strcmpi() ignores case
break;
}
if(i == 3) //If the login ID didn't match in any of the three cases
{
printf("Invalid login id\n");
getchar();
exit(0);
}
loginNumber = i; //need to store the subscript of the login ID
login[6] = '\0'; //NULL terminated string
printf("Enter the password\n");
while((temp = getc(stdin)) != '\n') // flush the input. Google it! Don't use fflush(stdin)
;
for(i=0; (temp = getch()) != '\r'; i++) //Loop executes till 'enter' is pressed
{
printf("*");
pass[i] = temp;// store character in pass
}
pass[6] = '\0';
if(!strcmp(passwords[loginNumber], pass))//compare with the appropriate loginID. Use strcmp
{
printf("\nAccess granted!\n");
getchar();
exit(0);
}
else
{
printf("\nAccess denied!\n");
getchar();
exit(0);
}
return 0;
}
The above code is still a li'l crappy since it uses non-portable getch(). I couldn't figure out any other way of getting the password without it being echoed to the screen. Maybe someone else will show a way.
The reason for not using scanf(or gets) can be found
here. You can read other related articles too over there.