0

Im trying to make a minutes and seconds timer but am having some trouble. The timer does not have to stop, as it will rarely go up to 5 mins.

Im trying to format it as mm:ss.

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

#define TRUE 1

int main( void ) {

    int min = 0;
    int sec = 0;


    while(TRUE){
    printf("%02d : %02d", min, sec);
    sec++;
    Sleep(1000); 
    if (sec == 59){
        min++;
        sec = 0;
    }


    } 
    return 0;
}

I've been trying this code but it does not seem to show the timer in the terminal when I run it.

ben04rogers
  • 65
  • 1
  • 11

1 Answers1

0

You have to either output entire lines of text or call fflush. Otherwise, printf just puts text into the output buffer.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278