Trying to create a program that reads words from a text file and outputs 20 password combinations with 4 words in each and with certain conditions such as no punctuation in word, no digits, and no characters other than the first may be uppercase. However, I am getting an exception thrown at ispunct(b[i]) and I think it has to do with the changing sizes of the words but I am not sure. Any help would be appreciated as my knowledge with C++ is rudimentary at best.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
bool acceptWord(string a, string b) {
if (b.length() > 3) {
for (int i = b.length() - 1; i; --i) {
if (ispunct(b[i])) {
return false;
}
if (isdigit(b[i])) {
return false;
}
}
if (isalpha(b[0]) && isupper(b[0])) {
for (int i = b.length(); i; --i) {
if (isupper(b[i])) {
return false;
}
}
}
a = b;
return true;
}
else {
return false;
}
}
int main()
{
fstream file;
string word, filename;
vector<string> tokens;
int random = rand() % 81;
filename = "input.txt";
file.open(filename.c_str());
if (!file.is_open()) {
cout << "File not found" << endl;
exit(1);
}
while (file >> word)
{
string token = "";
if (acceptWord(token, word)) {
for (int i = 0; i < 80; ++i) {
tokens[i] = token;
}
}
for (int i = 0; i < 20; ++i) {
cout << tokens[random] + " " + tokens[random] + " " + tokens[random] + " " + tokens[random] + "1" << endl;
}
}
return 0;
}