• printf固定一行打印倒计时的实现


    主要是依赖函数:printf("") 退格格式符

    fflush(stdout),刷新标准输出缓冲区,把输出缓冲区里的东西打印到标准输出设备上

    示例:

     1 #include<stdlib.h>
     2 #include <stdio.h>
     3 #include <time.h>
     4 #include <windows.h>
     5 
     6 
     7 
     8 int main()
     9 {
    10     int i;
    11 
    12 #if 1
    13     int bootdelay = 3;
    14     printf("Hit any key to stop autoboot: %2ds ", bootdelay);    //"%2ds " 2byte数字 1字节's' 1字节空格
    15     fflush(stdout);
    16     while(bootdelay > 0)
    17     {
    18         Sleep(1000);
    19         --bootdelay;
    20         printf("%2ds ", bootdelay);    //因格式占4byte,2byte数字、1字节‘s’、1字节空格,所以需要4个'' backspace 退格非删除
    21         fflush(stdout);
    22     }
    23 #endif
    24     printf("
    ");
    25     
    26     printf(".................
    ");
    27     for(i = 5; i > -1; i--)
    28     {
    29         if(i == 5)
    30         {
    31             printf("Wait %ds", i);
    32             fflush(stdout);
    33             Sleep(1000);
    34         }
    35         else
    36         {
    37             printf("%ds", i);
    38             fflush(stdout);
    39             Sleep(1000);
    40         }
    41     }
    42     
    43     printf("
    ");    
    44     
    45     return 0;
    46 }
  • 相关阅读:
    MySQL 处理重复数据
    MySQL 序列使用
    MySQL 元数据
    MySQL 临时表和复制表
    MySQL 索引
    MySQL ALTER命令-修改数据表名或者修改数据表字段
    MySQL 事务
    MySQL 正则表达式
    MySQL NULL 值处理
    MySQL 排序
  • 原文地址:https://www.cnblogs.com/skullboyer/p/11188447.html
Copyright © 2020-2023  润新知