关于C语言中delay的用法

夹心饼干 2008-08-06 04:03:28
void main()
{
int i;
char str[] = "what are you fucking doing ?";
int len = sizeof(str)/sizeof(char);
for(i=0; i<len; i++)
{
if(str[i]!=' '&& str[i]!='\0')
{
delay(10000);//此处是有延时的效果,但是不是我想要的每输出一个字符就延时
而是一组后延时,请问这个库函数的用法及实现
}
printf("%c",str[i]);
}
getch();
}
...全文
2517 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
PhoenixCao_ 2009-09-17
  • 打赏
  • 举报
回复

#include "stdio.h"
#include "time.h"

void wait( int ms );
void AuthorInformation();
int main(void)
{
AuthorInformation();
return 0;
}

void wait( int ms )
{
clock_t endwait;

endwait = clock() + ms * CLOCKS_PER_SEC / 1000;//CLOCKS_PER_SEC宏定义1000,标准时间差

while( clock() < endwait);
}
void AuthorInformation()
{
int i, j;
char cInfor[11][55] = {"\n\n\t\t Welcome To Use This Program.\n\n",
"\n\t Editor:Caoyongzhe \n\n",
"\n\t* Department :Computer Of Science and Technology ",
"\n\t* Profession :Software Engineering ",
"\n\t* Class :08505 ",
"\n\t* N0 :08110650501 ",
"\n\t* Task :commissary in charge of studies ",
"\n\t* City :Dalian ",
"\n\t* Contact :QQ:287983014 ",
"\n\t* Tel :1894098477* ",
"\n\t*Welcome to use it next time! "
};
int len = sizeof(cInfor)/sizeof(char);
for(j = 0; j < 11; j++)
{
for(i = 0; i < 55; i++)
{
if(cInfor[j][i] != '\0')
{
wait( 100 );
}
printf("%c", cInfor[j][i]);
}
}
}
bitxinhai 2008-08-06
  • 打赏
  • 举报
回复
库函数的实现‘:
应该是先获取系统的然后根据时钟频率计算时间就行了@!@!
linzsoft 2008-08-06
  • 打赏
  • 举报
回复
试一下

...
printf("%c",str[i]);
fflush(stdout);
...
_石头_ 2008-08-06
  • 打赏
  • 举报
回复
退出windows系统,直接进入dos然后运行你的程序!你的问题就解决了!
lunarfan 2008-08-06
  • 打赏
  • 举报
回复
第一反应设置个计数器
夹心饼干 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tianyazifan 的回复:]
你写的就是一个一个的延迟。只是计算机反映问题。如果把delay(10000)改为100000,效果就出来了。
void main()
{
int i;
char str[] = "what are you fucking doing ?";
int len = sizeof(str)/sizeof(char);
for(i=0; i <len; i++)
{
if(str[i]!=' '&& str[i]!='\0')
{
delay(100000);
}
delay(100000);
printf("%c",str[i]);
}
getch();
}
[/Quote]头文件我都包含全部了,但是我用100000的时候反映出来的是,后面有的一下显示出几个字符
根本没达到要求啊,而且如果是100000的话就应该延时10s,但是也不是啊
是不是我的用法有问题啊
_石头_ 2008-08-06
  • 打赏
  • 举报
回复
代码没问题啊!是不是你的编译器有问题啊!或者你没有吧dos.h头文件包含进来!
tianyazifan 2008-08-06
  • 打赏
  • 举报
回复
你写的就是一个一个的延迟。只是计算机反映问题。如果把delay(10000)改为100000,效果就出来了。
void main()
{
int i;
char str[] = "what are you fucking doing ?";
int len = sizeof(str)/sizeof(char);
for(i=0; i <len; i++)
{
if(str[i]!=' '&& str[i]!='\0')
{
delay(100000);
}
delay(100000);
printf("%c",str[i]);
}
getch();
}
yuwei2589 2008-08-06
  • 打赏
  • 举报
回复
每输出一个字符就延时
taojian_hhu 2008-08-06
  • 打赏
  • 举报
回复
设置一个计数器,然后在if语句中判断一下啊

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧