'Elegant Text Animation in C
Is there any way to animate a text output in C? I am relatively new to programming and am trying to accomplish something similar to this bit of python code but haven't been able to find anything online. All insights are welcome. Thank you for reading.
#python text animation
import time
import sys
def delay_print(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(0.02)
delay_print("hello world")
Solution 1:[1]
Here is an example:
#include <stdio.h>
#include <unistd.h>
void delay_print(char *str)
{
for (char *p = str; *p; p++) {
putchar(*p);
fflush(stdout);
usleep(20000);
}
putchar('\n');
}
int main(void)
{
delay_print("Hello world!")
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SGeorgiades |
