#include
#include
#include
#include
#include
const unsigned int LOW = 32;
const unsigned int HIGH = 127;
const unsigned int VALID_ARG_COUNT = 6;
void GenerateWordFile(const unsigned int, const unsigned int, const std::string, const std::string, const std::string);
int main(int argc, char **argv)
{
if (argc != VALID_ARG_COUNT)
{
std::cout << "Usage: " << argv[0] " << std::endl;
}
else
{
std::srand(GetTickCount());
GenerateWordFile(atoi(argv[1]), atoi(argv[2]), argv[3], argv[4], argv[5]);
}
return 0;
}
static std::string GenerateRandomWord(const unsigned int length, const unsigned int low, const unsigned int high)
{
std::string randomWord(length, '?');
for (unsigned int index = 0; index < length; index++)
{
randomWord[index] = low + std::rand() % (high - low + 1);
}
return randomWord;
}
void GenerateWordFile(const unsigned int numberOfLines, const unsigned int randomTextLength, const std::string textLeft, const std::string textRight, const std::string outputFile)
{
try
{
std::ofstream output;
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
output.open(outputFile.c_str());
for (unsigned int index = 0; index < numberOfLines; index++)
{
std::string word = GenerateRandomWord(randomTextLength, LOW, HIGH);
output << textLeft << word << textRight << std::endl;
}
output.close();
}
catch (std::ios_base::failure)
{
std::cout << "Opening file " << outputFile << " failed!" << std::endl;
}
}