|
发表于 2019-9-16 10:25:38
|
显示全部楼层
本帖最后由 superbe 于 2019-9-16 16:58 编辑
- #include <stdio.h>
- #include <conio.h>
- #include <windows.h>
- #include <process.h>
- void getInput(PVOID pvoid)
- {
- char ch;
- while(1)
- {
- ch=getch();
- *(char *)pvoid=ch;
- if(ch=='s') _endthread();
- }
- }
- int main()
- {
- char ch=0;
- int i = 0;
- int again=1;
- int tab[5]={1,2,3,4,5};
- _beginthread(getInput,0,&ch);
- while (again){
- printf("%d\n",tab[i++]);
- switch(ch)
- {
- case 'a':
- printf("按下了 A\n");
- break;
- case 'b':
- printf("按下了 B\n");
- break;
- case 's':
- again=0;
- break;
- }
- ch=0;
- if(i==5) i=0;
- Sleep(500);
- }
- return 0;
- }
复制代码
vs2012和dev-c++下测试通过。vc6要设置下才能编译。 |
|