random array index returning values not contained

For kicks I wrote up a Password generator after lunch. Let me start with the code:

unsigned int x,y,z,c;

unsigned int KISS();
unsigned int devrand();

int main( int argc, char** argv )
{
    int i, j = 1;
    char pwd[] = "abcdefghijklmnopqrstuvwxyz"
                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                 "1234567890"
                 "!@#$";
    char password[12];

    if( argv[1] )
        j = atoi(argv[1]);

    do {
        memset( password, '\0', sizeof(password) );
        for( i = 0; i < sizeof(password); ++i )
            password = (char)pwd[(KISS() % strlen( pwd ))];
        printf("%s\n", password);
        --j;
    } while( j );

    return 0;
}
/*
 * Fairly popular Random Number generator
 */
unsigned int KISS()
{
    x = devrand();
    while(!(y=devrand())); // y must not be zero
    z = devrand();
    c = devrand();

    unsigned long long t;
    unsigned long long a = 698769069ULL;

    x = 69069*x + 12345;

    y ^= (y<<13);
    y ^= (y>>17);
    y ^= (y<<5);

    t = a*z+c;
    c = (t>>32);

    return x+y+(z=t);
}


/*
 * using a perfectly fine generator to generate a seed >.>"
 */
unsigned int devrand( void )
{
    int          f;
    unsigned int r;
    f=open("/dev/urandom", O_RDONLY);

    if( f == -1)          exit(-1); // ERROR?
    if( read(f,&r,4)!=4 ) exit(-1); // ERROR?

    close(f);
    return r;
}

( all there upon request )

Now this works just fine without issues but if I specify my array 'password' to be of say size 9 the program starts returning values not within the 'pwd' array.

Ive had it return quotes brackets and a bunch of various non printables.

Any idea's?

Post the entire code. You are missing the code listing for the random number generator KISS_RNG.

I tried just posting what was relevant but give me a sec.

Here is an example crap output with password[9]

You cant see it but there is some control character after the '-'

---- BIG EDIT ----

I think the code is eating the ending NULL Character as The output from 9 is longer than 9 characters which would explain why I get this crappy output

---

So the fix is subtracting 1 from sizeof( password )

Sorry, I oopsed all over this forum with a rookie mistake.

Some points:

You can't place more then 10 chars in the string password:

for( i = 0; i < sizeof(password)-1; ++i )

You must end the string with a NULL character before the printf statement.

password[i+1] = '\0'
printf("%s\n", password);

Regards

My memset sets the whole string to NULL for each password we decide to generate so just subtracting from sizeof() should be the end of it right?

But as a best practice Its probably best to do it the way you have said as I'm sure my memset is eating cpu time for no reason.

Better to use what Franklin52 suggested instead of setting all locations to NULL with memset.