Hello,
A simple program I am writing uses a struct to store a key and key size variable. However I get an error that states that my struct variable is being used without being initialized... I dont really know why it is telling me that.
Code:keygen.hpp
#include <ctime>
#include <cstdlib>
#include <string>
#define KEY_SIZE_128 16
#define KEY_SIZE_192 24
#define KEY_SIZE_256 32
#define KEYBOARD_CHARS "`1234567890-=+_)(*&^%$#@!~[]\\|}{"
typedef struct KeyInfo {
char Key[32];
int KeySize;
};
/* Generates a random key. */
void GenerateKey(KeyInfo keyInfo, int keySize);
keygen.cpp
#include "keygen.hpp"
/* Generates a random key. */
void GenerateKey(KeyInfo keyInfo, int keySize)
{
int random;
time_t ltime;
keyInfo.KeySize = keySize;
srand(time(<ime));
for (int i = 0; i < keySize; i++)
{
random = rand() % strlen(KEYBOARD_CHARS) + 1;
keyInfo.Key[i] = KEYBOARD_CHARS[random];
}
}
main.cpp
#include <iostream>
using namespace std;
#include "keygen.hpp"
int main()
{
struct KeyInfo key;
GenerateKey(key, KEY_SIZE_128);
for (int i = 0; i < key.KeySize; i++)
cout << key.Key[i] << " ";
cin.get();
}
How do I initialize a struct then?