多线程实现变色龙
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"); }
相关文章推荐
- json_decode()和json_encode()的使用方法
- java基础tips
- Android二维码扫描、生成
- Android二维码扫描、生成
- jabref【参考文献生成,抓去,推送,管理工具】简介
- AS通过git clone 项目代码
- laravel环境搭建
- git tag 打标签
- [SDCC讲师专访]阿里王晶昱:云时代的分布式数据库DRDS
- Android 进阶 教你打造 Android 中的 IOC 框架 【ViewInject】 (上)
- iOS关键字strong/weak/assign/retain/nonatomic/atomic
- 判断字符串是否为null,使用 == 号
- H264 NAL头解析
- Swift自定义UITableView、UICollectionView
- jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)
- 提升SQL语句的查询性能
- ubuntu14.04解决记事本乱码问题
- Tomcat中更改网站根目录和默认页的配置方法
- 让git忽略掉文件权限检查
- 随记(一)