求C语言大神帮助,关于一道编程题,该如何解决

求C语言大神帮助,关于一道编程题
我想模拟手机的那个数字键盘来输入字母,比如说按1次1是a,按2次1是b,按3次1是c..。但是我不知道到怎么去记录时间间隔,就是说快速按3次1可以显示c,但是如果只连续按2次1,(稍作停顿后)第三次再按1的是后就是b了。当然如果能够实现连续按2次1,稍作停顿,不用再按键就可以显示b那就更好了。


#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>

void PRINTF(int *num);

int main(void)
{
time_t t1, t2, t3;
int num[10];
char ch;

ch = getch();
t1 = t2 = clock();
while (ch>='0' && ch<='9')
{
t2 = clock();
if (difftime(t2, t1) >= 3)
PRINTF(num);

num[ch-'0']++;

t1 = t2 = clock();
ch = getch();

}

return 0;
}

void PRINTF(int *a)
{
if (a[0] >= 1)
{
printf(" ");
a[0] = 0;
}
else if (a[2] == 1)
{
printf("a");
a[2] = 0;
}
else if (a[2] == 2)
{
printf("b");
a[2] = 0;
}
else if (a[2] == 3)
{
printf("c");
a[2] = 0;
}
else if (a[3] == 1)
{
printf("d");
a[3] = 0;
}
else if (a[3] == 2)
{
printf("e");
a[3] = 0;
}
else if (a[3] == 3)
{
printf("f");
a[3] = 0;
}
else if (a[4] == 1)
{
printf("g");
a[4] = 0;
}
else if (a[4] == 2)
{
printf("h");
a[4] = 0;
}
else if (a[4] == 3)
{
printf("i");
a[4] = 0;
}
else if (a[5] == 1)
{
printf("j");
a[5] = 0;
}
else if (a[5] == 2)
{
printf("k");
a[5] = 0;
}
else if (a[5] == 3)
{
printf("l");
a[5] = 0;
}
else if (a[6] == 1)
{
printf("m");
a[6] = 0;
}
else if (a[6] == 2)
{
printf("n");
a[6] = 0;
}
else if (a[6] == 3)
{
printf("o");
a[6] = 0;
}
else if (a[7] == 1)
{
printf("p");
a[7] = 0;
}
else if (a[7] == 2)
{
printf("q");
a[7] = 0;
}
else if (a[7] == 3)
{
printf("r");
a[7] = 0;
}
else if (a[7] == 4)
{
printf("s");
a[7] = 0;
}
else if (a[8] == 1)
{
printf("t");
a[8] = 0;
}
else if (a[8] == 2)
{
printf("u");
a[8] = 0;
}
else if (a[8] == 3)
{
printf("v");
a[8] = 0;
}
else if (a[9] == 1)
{
printf("w");
a[9] = 0;
}
else if (a[9] == 2)
{
printf("x");
a[9] = 0;
}
else if (a[9] == 3)
{
printf("y");
a[9] = 0;
}
else if (a[9] == 4)
{
printf("z");
a[9] = 0;
}

}

这是我的代码,当然这个实现不了我说的那个功能,因为每次是按下回车后程序会自动跑起来,t2和t1之差永远不会大于3.能不能帮我改改,如果改不了,全部重写也可以
------解决方案--------------------
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

/* 超过1000ms认为超时输出 */
#define TIME_OVER 1000

/* key按下了count次,根据你自己的要求做按键解码,比如key='1',count=2表示字母b,自己做处理 */
void translate_key(int key, int count)
{
printf("Pressed %c key %d count\r\n",(char)key, count);
}


void main()
{
int iPrevKey, iCurKey;
int iPressCount;
time_t tPrevTime;

iPressCount = 0;
iCurKey = -1;
while(1)
{
if(_kbhit())
{
iCurKey = _getch();
tPrevTime = clock();
/* 如果新按键首次按下 */
if(iPressCount == 0)
{
iPrevKey = iCurKey;
iPressCount++;
}
else
{
/* 如果该次按键和上次不一样,输出上次按键,并重新记录该次按键 */
if(iPrevKey != iCurKey)
{
translate_key(iPrevKey, iPressCount);
iPrevKey = iCurKey;
iPressCount = 1;
}
/* 按键一样,记录次数 */
else
{
iPressCount++;
}
}
}
/* 超时且有按键按下,输出 */
else if((iCurKey != (-1)) && ((clock() - tPrevTime) > TIME_OVER))
{
translate_key(iCurKey, iPressCount);
iPressCount = 0;
iCurKey = -1;
}
}
}

------解决方案--------------------
参考《编译原理》中的词法分析和有限状态自动机。