I made some programs in C using Dev C++ that use the usleep
function, which prints characters individually slower or faster, set by a number I want:
void lyrics(char *s, unsigned ms_delay){
unsigned usecs = ms_delay * 1000; /* 1000 microseconds per ms */
for (; *s; s++) {
putchar(*s);
fflush(stdout);
usleep(usecs);
}
}
When I ran them on Windows 7 they were perfect and the times were respected.
On Windows 10, it just prints the characters very slowly, 1 being the fastest, but still way slower than it should.
I've tried running as an admin, compatibility mode, affinity to 1 CPU core but those don't seem to work, and I don't have much knowledge of C to try other methods.
And it's used here to print each character at a certain speed, 200ms each being the slowest:
lyrics("We are ", 150);
lyrics("flying ", 190);
lyrics("high\n\n", 200);
Am I missing something or is it a Windows 10 thing?
I also am using C and not C++. A lot of the functions recommended and linked to my previous post are for C++ and will not run under C and vice-versa.
Edit: Minimal example code
#include <stdio.h>
void lyrics(char *s, unsigned ms_delay){
unsigned usecs = ms_delay * 1000;
for (; *s; s++) {
putchar(*s);
fflush(stdout);
usleep(usecs);
}
}
main(){
lyrics("\
DDDDDDDDD CCCCCCCCC XXX XXX\n\
DDDDDDDDDD CCCCCCCCC XXX XXX\n\
DDD DDDD CCCCC XXX XXX\n\", 1);
}
Edit 2: I found something peculiar. My program is quite extensive because it prints lyrics at different speeds and prints graphics made with ASCII.
When printing at 1, supposedly 1ms per character, it prints very slowly on 10, but when it plays the lyrics, it's the same speed as in 7. I changed the minimal code to reflect what I found and the videos below.
I also made a YouTube video showcasing my program before, which ran under Win7, and made a new one under 10 to show the difference and hopefully illustrate the situation better:
Under Win7 (normal)
I've tried to individually print each line with a 1, but it does the same thing.