随机生成26个小写字母和26个大写字母

来源:互联网 发布:淘宝聚划算怎么用 编辑:程序博客网 时间:2024/04/29 00:13
#include<stdio.h>

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]

0 0