注册 登录
编程论坛 C语言论坛

c语言 如何输出“abcdef”等待两秒钟后,用“12345”替换“abcde”,最终显示“12345f”?

汽水菠萝 发布于 2020-04-30 14:49, 3788 次点击
#include <stdio.h>
#include <time.h>
int main()
{
    int k,l,m,n,h;        
    char c,p,y,x,a,j;
后面就不知道怎么写了,就直接加printf("\r12345\n")?
   





不确定要不要加上(include<time.h>
替换的话要用到printf("\r12345\n")
等待两秒钟要执行一个死循环,我不明白怎么设置一个可以执行一次一秒钟的死循环?

[此贴子已经被作者于2020-4-30 14:54编辑过]

11 回复
#2
lin51616782020-04-30 15:40
循环开始之前 clock 获取时间
循环中不停 clock 获取时间
比较两个时间相差2秒 就退出循环


#3
汽水菠萝2020-04-30 16:03
回复 2楼 lin5161678
抱歉我不太明白您的意思,可以写具体一点吗?
#4
吹水佬2020-04-30 16:10
t1 = 当前时间
while 当前时间 - t1 < 2秒;
s = "abcdef"
memmove s, "12345", 5
printf s
#5
汽水菠萝2020-04-30 16:40

    int a;
   
     a=clock();
     printf("%d\n,a");
     a=a+1;
     while(a<=2)
     printf("%d秒\n",a);
这样写可以吗
   
#6
lin51616782020-04-30 16:49
回复 4楼 吹水佬
应该是要在同一行修改显示数据
#7
wmf20142020-04-30 16:53
#include <stdio.h>
#include <time.h>
int main()
{
    int t;
    t=clock();
    printf("abcdef");
    while(clock()-t<2000); //clock()得到的是毫秒级别的时钟计数
    printf("%c12345\n",(char)13);  //显示asc码13等同于\r
    return 0;
}
#8
lin51616782020-04-30 16:54
程序代码:
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
    clock_t begin = clock();
    printf("abcdef");
    while((clock() - begin) / CLOCKS_PER_SEC < 2)
        ;
    printf("\r12345\n");
   
    return 0;
}
#9
汽水菠萝2020-04-30 17:13
回复 7楼 wmf2014
这样是显示有错误哎
#10
汽水菠萝2020-04-30 17:14
回复 8楼 lin5161678
这样的话没有用到break跳出循环哎,怎么办?
#11
汽水菠萝2020-04-30 17:17
#include <stdio.h>
#include <windows.h>
int main()
{
    printf("abcdef");
    Sleep(2000);
    printf("\r12345\n");
}
麻烦大家帮我看一下对于这个程序可以修改加上clock函数吗?谢谢各位了
#12
汽水菠萝2020-04-30 17:20
#include <stdio.h>
#include <time.h>
int main()
{
    printf("abcdef");
    {
    int t;
    t=clock();
    while(clock()-t<2000);
    }
    printf("\r12345\n");
}
我这样写好像可以了!谢谢各位了!
1