I am having trouble with a two-dimensional array comparison. I need to create a pseudo login system that asks the user for a username and password and then compares the input to a predefined list of usernames.
In the function, the predefined usernames are represented by the *s
and the user input is *s1
. When I try to compile it, this pesky trouble-maker appears:
68 D:\Personal\Dev-Cpp\projects\loginSysTest\main.cpp invalid conversion from
char' to
const
regarding the strncmp
function in the if
statement.
This is the code:
#define nameLenght 30
#define User 10
char usernames[User][User] = {{"student"}, {"admin"}, {"Deus Ex Machina"}};
//=====================================================================
int main(int argc, char *argv[])
{
char usernameInput[nameLenght + 1] = {0};
gets(usernameInput);
int login = compS(*usernames, usernameInput);
if(login == 0)
printf("Access Granted! \n");
else
printf("Access Denied!");
system("PAUSE");
return 0;
}
//=====================================================================
int compS(char *s, char *s1)
{
for(int k = 0 ;k < nameLenght; k++)
{
if(strncmp(s[k], s1, strlen(s1)) == 0)
return 1;
}
}
Thank you in advance.