您的位置:首页 > 编程语言 > C语言/C++

15.C语言多线程实现变色龙以及cmd窗口标题变化

2017-12-30 18:31 274 查看
1 #define _CRT_SECURE_NO_WARNINGS
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <Windows.h>
6 #include <process.h>
7 #include <time.h>
8
9 void title(void *p)
10 {
11     char title[100];
12     int i = 0;
13
14     while (1)
15     {
16         sprintf(title, "title 程序已经运行了%d秒", i);
17         system(title);
18         i++;
19         Sleep(1000);
20     }
21
22 }
23
24 void color_change(void *p)
25 {
26     char color[100];
27     srand(time(0));
28     while (1)
29     {
30         int num1 = rand() % 16;
31         int num2 = rand() % 16;
32         sprintf(color, "color %x%x", num1, num2);
33         system(color);
34         Sleep(1000);
35     }
36 }
37
38 void main()
39 {
40     _beginthread(title, 0, NULL);
41     _beginthread(color_change, 0, NULL);
42
43
44     system("pause");
45 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: