Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

The sleep function is not functioning as expected

$
0
0

The sleep function here is functioning differently on Windows and Linux.

#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>#include <unistd.h>int main(){printf("Press 1 to apply for Password Change Request...\n");                printf("\nPress any other key to try again");                fflush(stdout);                for(int j=0; j<2; j++)                {                        sleep(1);                        printf("..");                }}return 0;

On Windows, it is working as it is meant to, waiting for a second then printing .. and then again waiting for a second and then printing ...But on Linux, it is waiting for whole 2 seconds and then printing .... altogether.

What should I do to fix it?

I am using MinGW on Windows.


Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>