免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1307 | 回复: 1
打印 上一主题 下一主题

请教如何在自己编写的终端程序中响应ESC键 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-22 12:33 |只看该作者 |倒序浏览
发现用getchar()之类的函数不行

论坛徽章:
0
2 [报告]
发表于 2006-08-22 13:01 |只看该作者
可不可以用信号
软中断!


  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <unistd.h>

  6. #define Message "Do you want stop?"

  7. char *message=Message;

  8. void ctrl_c_op(int signo)
  9. {

  10. write(STDERR_FILENO,message,strlen(message));


  11. }
  12. main()
  13. {

  14. struct sigaction action;

  15. action.sa_handler=ctrl_c_op;

  16. sigemptyset(&action.sa_mask);

  17. action.sa_flags=0;

  18. if(sigaction(SIGINT,&action,NULL)<0)
  19. {


  20. fprintf(stderr,"error");

  21. exit(1);
  22. }



  23. while(1)
  24. {



  25. }







  26. }






复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP