繁体   English   中英

如何创建一个每次运行代码时都会更改其值的 char 数组变量?

[英]How can I create a char array variable that changes its value every time I run the code?

我正在使用这样声明的 char 数组变量:

char our_thread[8]="thread1";

我将它用于创建线程的 function 中:

kthread_create(thread_fn,NULL,our_thread);

该线程将在进程列表中命名为“thread1”。

我想将thread1 char数组变量更改为动态变量,以便每次创建线程时都会有另一个名称而不是“thread1”。

谢谢你。

这个问题有点宽泛,但无论如何这可能会有所帮助:

char our_thread[20];

for (int i = 0; i < 100; i++)
{
  sprintf(out_thread, "thread%d", rand() % 100);
  printf("thread name %s\n", our_thread);
}

您应该能够找出 rest。

阅读randsprintf的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM