-1

I was trying to create a clock program with c using the eclipse ide. When I run the program it keeps executing every single count. I used system("cls"). Also tried "clear" It shows no error but it is not working. I want the screen cleared after every count. It is showing a ⍰ symbol sometimes. https://i.stack.imgur.com/0ElDL.png ---This is what I got.

int main(void)
{

    int hour,minute,second;
    hour=minute=second=0; 
    setbuf(stdout,NULL);  

    while(1) 
    {

        system("cls");  

        printf("%02d:%02d:%02d\n",hour,minute,second);  

        fflush(stdout); 

        second++;  

        if(second==60)

        {
            minute += 1; 
            second=0;   
        }

        if(minute==60)

        {
            hour += 1; 
            minute=0; 
        }

        if(hour==24)

        {
            hour=0;
            minute=0;
            second=0;

        }

        sleep(1); 
    }

       return 0;

.

2 Answers2

0

try using system("clear");

Harish
  • 85
  • 14
0

According to example published above you need only one line to display clock. It's easier to add carriage return:

while(1) 
{
        printf("%02d:%02d:%02d\r",hour,minute,second);  
        fflush(stdout); 
        ...
}
nvf
  • 465
  • 1
  • 7