I want to print a sequence of characters one by one in the same place. I print one letter, then wait 1 second with sleep, move cursor one column left using console code, print next letter and so on. The problem is as a result program waits the sum of all sleeps (2s in my example) and then prints only the last character ('y'). Same goes with nanosleep, waiting for a signal instead of sleeping. How to make it work?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
printf( "H" );
sleep( 1 );
printf( "\033[1D" );
printf( "e" );
sleep( 1 );
printf( "\033[1D" );
printf( "y" );
}