2-3 list2-8 逐个显示字符,再逐个消去

yuzuki_n / 2023-08-08 / 原文

#include <stdio.h>
#include <time.h>
#include <string.h>

// 等待x毫秒
int sleep(unsigned long x)
{
  clock_t c1 = clock(), c2;

  do {
    if ((c2 = clock()) == (clock_t) -1)
      return 0;
  } while ((c2 - c1) < x);
  return 1;
}

int main()
{

  int i;
  char name[] = "BohYoh Shibata";
  int name_len = strlen(name);
  while (1)
  {
    for (int i = 0; i < name_len; i++)
    {
      putchar(name[i]);
      fflush(stdout);
      sleep(500);
    }
    for (int i = 0; i < name_len; i++) {
      printf("\b \b");
      fflush(stdout);
      sleep(500);
    }
  }
}