char RandString();
int main( void )
{
int i=0;
char cTemp;
char sKey[9];
memset(&cTemp, 0, sizeof(cTemp));
memset(sKey, 0, sizeof(sKey));
srand((unsigned )time(NULL));
for(; i<8; i++)
{
cTemp = RandString();
sKey[i] = cTemp;
}
sKey[8]=‘\0‘;
printf("sKey[%s]\n", sKey);
return 0;
}
char RandString()
{
int j = rand()%2;
char temp;
int m = 0;
if( j==0 )
{
temp =‘a‘;
}
else
{
temp=‘A‘;
}
m = rand()%26;
temp = temp + m;
return temp;
}
运行结果:
sKey[ycePuTLP]
随机生成26个小写字母和26个大写字母,布布扣,bubuko.com
原文地址:http://blog.csdn.net/ssz912728941/article/details/36001857