易截截图软件、单文件、免安装、纯绿色、仅160KB

C Snippet #8(规定时间输入,否则默认跳转的实现)

http://www.ddj.com/cpp/221600722
Q: HOW DO I... put timers with default actions in my C code?
A: Many times, we need to write programs that will only wait a certain specified amount of time for a user to do something. After that time, we need to assume that the user isn't going to do anything and move on to some specified default action. This Snippet works exactly like the get_ch() function in most PC C compiler libraries, except that it will only wait as long as you tell it for the user to hit a key. If no key is pressed within the time limit, the function returns with an EOF. As usual, a test harness has been added to allow for stand-alone testing. To compile the stand-alone test, simply define the TEST macro.
/*
** TIMEGETC.C - waits for a given number of seconds for the user to press
** a key. Returns the key pressed, or EOF if time expires
**
** Public domain by Bob Jarvis
** Test harness added by Bob Stout
**
** Note: This relies on the non-standard kbhit() function, which is available
** in all Windows PC compilers - including MinGW32 (gcc).
*/
#include <stdio.h>
#include <time.h>
#include <conio.h>
int timed_getch(int n_seconds)
{
time_t start, now;
start = time(NULL);
now = start;
while(difftime(now, start) < (double)n_seconds && !kbhit())
{
now = time(NULL);
}
if(kbhit())
return getch();
else return EOF;
}
#ifdef TEST
main()
{
int c;
const char *ctrlchars[] =
{
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS_", "HT_", "LF_", "VT_", "FF_", "CR_", "SO_", "SI_",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM_", "SUB", "ESC", "FS_", "GS_", "RS_", "US_"
};

printf("Starting a 5 second delay...\n");
c = timed_getch(5);
if(c == EOF)
printf("Timer expired\n


相关文档:

Facts of C Programming Language

Facts of C Programming Language
C的一些掌故
(英文原文:http://www.programmingfacts.com/2009/12/01/facts-of-c-programming-language/)
C programming language was developed in 1972 by Dennis Ritchie and Brian Kernighan at the Bell Telephone Laboratories (AT&T Bell Laboratories) for use with the Un ......

Spring配C3P0连接池(以MySQL数据库配置为例)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jee="http://www.springframework.org/schema/jee"
      &nbs ......

C Sharp 限制修饰符

public可以被任意存取;
protected只可以被本类和其继承子类存取;
internal只可以被本组合体(Assembly)内所有的类存取,组合体是C#语言中类被组合后的逻辑单位和物理单位,其编译后的文件扩展名往往是“.DLL”或“.EXE”。
protected internal唯一的一种组合限制修饰符,它只可以被本组合体内 ......

TURBO C 2.0 文件分类

 
 2009-12-24          21:15:41
 
TURBO C 2.0 文件分类
 
·原创·
网上下载TURBO C 2.0很混乱,一直想把她整理一下,使各个实例分开,各个不同部分分开。断断续续花了很长时间,到今天终于整理完了。发帖出来给大家看看。有需要的 ......

C# 调用 c++ dll 的一些问题总结

1.c++的到处函数只要在函数申明的时候加个导出关键字就可以了
2.参数类型问题,
一般的c++中char * 对应 c#中的string
而c++中 char **类型的参数对应c#中 ref string 这种一般都是用来返回字符串的!
3.函数入口问题,一般会出现 "找不到入口点" 这个问题不是由你引起的,而是系统自己把名字改了,改成什么样的名字建议你用 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号