Hiya,
Say, I've got 500 passwords and usernames, for example:
"bss01, Boss of the year"
"mngr01, Manager of the month"
. . . . . . .
Q1:
Can I declare just one array for it?
Or do I have to have two pointers of array, like:-
Code:
char *passlist[] = {"bbbs01", "michelle01", "gwen07", "laura01"};
char *namelist[] = {"Baba BlackSheep", "Michelle Mystique", "Gwendoline Gorgio", "Laura Lavidd"};
So when the search password is found it displays the name that belongs to the password, for example if enter laura01 in the program it would display:-
Welcome: Laura Lavidd
Q2:
If I change the array into text file and then read it in for the program to search. How do I let the program know of how many names, or how big is the file?
Code:
//search for password
for (int p = 0; p <= 3; p++)
if (strcmpi(passlist[p], pword) == 0)
{
cout << "\n\nWelcome: " << namelist[p] << endl;
break;
}
if (strcmpi(passlist[p], pword) != 0)
cout << "\nPassword not found !!" << endl;
Here is my demo prog in BC ++, it works pretty well as is for now.
And thanks for any comments and advice you can give.
Code:
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char *passlist[] = {"bbbs01", "michelle01", "gwen07", "laura01"};
char *namelist[] = {"Baba BlackSheep", "Michelle Mystique", "Gwendoline Gorgio", "Laura Lavidd"};
int ch;
char pword[BUFSIZ];
int i = 0;
cout << "Enter your password: ";
while ((ch = getch()) != EOF
&& ch != '\n'
&& ch != '\r'
&& i < sizeof(pword) - 1)
{
if (ch == '\b' && i > 0)
{
putchar('\b ');
i--;
pword[i] = ch;
}
if (isalnum(ch))
{
putchar('*');
pword[i] = ch;
i++;
if (i >= 10) break;
}
}
pword[i] = '\0';
//search for password
for (int p = 0; p <= 3; p++)
if (strcmpi(passlist[p], pword) == 0)
{
cout << "\n\nWelcome: " << namelist[p] << endl;
break;
}
if (strcmpi(passlist[p], pword) != 0)
cout << "\nPassword not found !!" << endl;
return 0;
}