您的位置:首页 > 其它

多线程实现变色龙

2015-12-31 12:00 330 查看
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <process.h>
#include <time.h>

void timeset(void *p)//线程的main函数
{
int i = 0;
while (1)
{
i++;
char str[100] = { 0 };
sprintf(str, "title 当前时间第%d秒", i);
system(str);
Sleep(1000);
}

}

void colorall(void *p)
{
time_t ts;
unsigned int num = time(&ts);
srand(num);

for (;;)
{
int num1 = rand() % 16;
Sleep(10);
int num2 = rand() % 16;
char str[50] = { 0 };
sprintf(str, "color %x%x", num1, num2);//%x 转化成十六进制
system(str);
}
}

void main()
{
_beginthread(timeset, 0, NULL);
_beginthread(colorall, 0, NULL);

system("color 3f");
system("pause");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: