程序执行如下:
代码如下
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<process.h>
#include<time.h>
void timeset(void *p)
{
int i = 0;
while (1)
{
i++;
char str[100] = { 0 };
sprintf(str, TEXT("title 当前时间是%d秒"), i);
system(str);
Sleep(1000);
}
}
void colorAll(void *p)
{
time_t ts;
srand(time(&ts));
for (;;)
{
int num1 = rand() % 16;
Sleep(20);
int num2 = rand() % 16;
char str[50] = { 0 };
sprintf(str, TEXT("color %x%x"), num1, num2);
system(str);
}
}
void main()
{
_beginthread(timeset, 0, NULL);
_beginthread(colorAll, 0, NULL);
system("pause");
}
错误 原因,需要设置编码的方式
如下增加:
#include<locale.h>
函数:setlocale(LC_ALL, “ZH-CN”);
最后得到正确的结果