Im trying to write a program that takes a password created by a user and compares it to an array of strings. The password has to be a word not in the array. For example: The user enters the password "about" and that word is in the array so it will return "Wrong". What i've tried dosent work, Can someone help?
Here's everything i have so far:
int main()
{
int i;
char dict[998][15];
char password[30];
size_t ind;
FILE *fp = fopen("dictionary.txt", "r");
if (fp != NULL)
{
for (ind = 0; fgets(dict[ind], sizeof dict[0], fp) && ind < sizeof dict / sizeof dict[0]; ind++)
{
dict[ind][strcspn(dict[ind], "\n")] = '\0';
}
}
else
{
printf("Error opening file");
}
fclose(fp);
printf("Please enter Password: ");
scanf("%s",password);
//Checking if password is in array.
for (size_t i = 0; i < ind; i++)
{
if (!strcmp(password, dict[i]))
{
printf("Wrong");
}
else
{
printf("Correct");
}
}
}