Aug 24, 2009 at 4:06pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
include <cstring>
#include <iostream>
#include <ctime>
#include <cstdlib>
int main(void )
{
using namespace std;
srand(unsigned int (time(0)));
unsigned n = 1234567890;
char buf[rand() % 255 + 1];
_itoa(n, buf, 62);
cout << "Your Password is: " << buf << "\n" ;
system("pause" );
return 0;
}
(11) : error C2057: expected constant expression
(11) : error C2466: cannot allocate an array of constant size 0
(11) : error C2133: 'buf' : unknown sizeI have the errors:
I know what the problem is but I don't how to fix it.
Last edited on Aug 24, 2009 at 4:17pm UTC
Aug 24, 2009 at 4:11pm UTC
I'm not clear on what your asking. Are you looking to populate the char array with random numbers?
Aug 24, 2009 at 4:21pm UTC
Exactly, and make the program print out random characters.
I did the array part already, but I can't get it to print random characters.
Aug 24, 2009 at 5:39pm UTC
On line 11 you are allocating a char array with a non-constant size. If you want a dynamic size, you need to use dynamic allocation.
char *buf = new char [rand % 255 + 1];