#include<stdio.h>
#include<windows.h>//Sleep(),PlaySound()
void _TextShow(char *,int,int);
int main()
{
char text1[]="As food is to the body, so is learning to the mind.";
char text2[]="Our bodies grow and muscles develop with the intake of adequate nutritious food.";
char text3[]="这是我写的一个简单的例程";
char text4[]="模拟键盘打字,敲击声中慢慢展开文字";
_TextShow(text1,sizeof(text1),80);
_TextShow(text2,sizeof(text2),80);
_TextShow(text3,sizeof(text3),80);
_TextShow(text4,sizeof(text4),80);
getchar();
return 0;
}
void _TextShow(char str[],int max,int speed)
{
int i;//循环变量
PlaySound(TEXT("Keyboard.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);//播放敲击键盘的声音
//开始一个一个输出文字
for(i=0;i<max;i++){
printf("%c",str[i]);//将数组中第i个字符打印出来
if(i==max-1){
printf("\n");//如果一句话输出完了,换行
}
Sleep(speed);//输出每个字之间暂停一小段时间
}
PlaySound(0,NULL,SND_FILENAME|SND_ASYNC);//一句话敲完,停止播放敲击声
}