Just thought I'd suggest the following:

Code:
By lepricaun

void generate_password(length)
{
    int length;
    srand(time(NULL));    
    while (length>0)
    {
        
        int cha;
        cha=rand()%128;
        if((cha>=48 && cha<=57) || (cha>=65 && cha<=90) || (cha>=97 && cha<=122))
        {
           printf("%c",cha);
           length--;
        }
    }
}
Yes this works, however, should you be declaring the cha variable every time you loop round in the while loop? It's not efficient. 9/10 from me, especially as you didn't do that in the code this superceeded! LOL