随机生成长为1…16的字符串,用C语言怎么做?

来源:百度知道 编辑:UC知道 时间:2024/06/14 13:17:09

事出匆忙,这里只搞了一个大写的,如果你还有什么要求,我可以改或者讲解给你,还有这个程序是大二水平的

#include<stdio.h>
#include<malloc.h>
#include<time.h>
#include<stdlib.h>

#define NULL 0

struct ch
{
char cha;
struct ch*next;
};
struct ch*head=NULL,*p;

void main()
{

int len,i,c;
char ch=0;
srand( (unsigned)time( NULL ));
len=1+rand()%16;
for(i=0;i<len;++i)
{
if(head==NULL)
{
head=(struct ch*)malloc(sizeof(struct ch));
c=65+rand()%26;
head->cha=c;
head->next=NULL;
p=head;
}
else
{
p->next=(struct ch*)malloc(sizeof(struct ch));
p=p->next;
c=65+rand()%26;
p->cha=c;
p->next=NULL;
}
}
for(p=head;p!=NULL;p=p->next)
printf("%c",p->cha);
}

#include <stdio.h>

void fac(int n);
i