Hi!
I am making a program that generates a random 10 character length password that should be legible according to English pronunciation laws, but I don't know if I should use a string or a char. So far I have a program that generates a random series of characters, but the output is a bunch of strange characters and I don't know why. Can someone help me?
char first[6] = { 'ab', 'ho', 'fr', 'de', 'li', 'me' }; none of the syllables is a proper char. So this is your first mistake. If you wish to store more than one character in a variable, use a string, or in this example array of strings: string first[6] = { "ab", "ho", "fr", "de", "li", "me' }; // note double quotes . (You could use char[][], but why bother?)
Then use your modulo correctly: first[rand() % 25]; may be equal to e.g. first[20]; (It's a random number between 0 and 24) which is out of bounds of first, so that's where all the junk come to your output from.
Thank you both for your help!
One more question: how do I set a length for the string? I want to make it so it's only 10 characters long, and right now it generates a password using 2 of each of the array elements.
#include <iostream>
#include <cstring>
#include <ctime>
#include <cstdlib>
using namespace std;