封獣鵺 2022-01-26 16:53 采纳率: 100%
浏览 71
已结题

随机输出unicode中的任意字符

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
char u[17]="0123456789abcdef";
long bitcount = 0;
printf("请输入要生成的文字的字节数:");
scanf("%ld",&bitcount);
char uni[5]="0000";
int i;
int j;
for(i=0;i<bitcount;i++)
{
srand(time(NULL));
for(j=0;j<4;j++)
{
uni[j]=u[rand()%16];
}
printf("\u%c%c%c%c",uni[0],uni[1],uni[2],uni[3]);
return 0;
}

  • 写回答

2条回答 默认 最新

  • 封獣鵺 2022-01-27 17:29
    关注
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    int main(void)
    {
        srand((unsigned int)time(NULL));
        long bitcount = 0;
        printf("请输入要生成的文字的字节数:\n");
        scanf("%ld",&bitcount);
        long i;
        long t;
        for(i=0;i<bitcount;i++)
        {
            t = rand()%0x10000;
            printf("%c",t);
        }
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 1月27日
  • 已采纳回答 1月27日
  • 请详细说明问题背景 1月26日
  • 创建了问题 1月26日

悬赏问题

  • ¥15 hexo+github部署博客
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?