Thread: how to fix this problem in my clock Programme ?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    9

    how to fix this problem in my clock Programme ?

    the execute file of this programme works .. the programme works well ...

    the only problem i have is that after 1st minute ... for all the next minutes the first 10 seconds appear me as 19 , 29 , 39 , 49, 59, 69 , 79, 89, 99 ,109, 11 ,12 ,13, ,.......

    and after those 10 secs it works fine .....

    can some one help me ?
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>

    int main(){

    //Variabili di OUTPUT

    int sec,min,h;

    //Inizio Algoritmo
    sec=0;
    min=0;
    h=0;
    do{
    _sleep(1000);
    sec=sec+1;
    if(sec==60){
    sec=0;
    min=min+1;
    if(min==60){
    h=h+1;
    min=0;
    sec=0;
    }
    }
    printf("\r%d : %d : %d",h,min,sec);
    }while(h<=24);

    }
    Attached Files Attached Files

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Use code tags when you post code:

    Announcements - General Programming Boards

    Main() should return an int.

    You may want to try this as a format string:

    Code:
    %d : %02d : %02d
    However, I do not notice the problem you mention.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    9

    tnx

    thnx man .. but how did u understand tht mistake ... and without that one why doesnt it works ??

    im at start with programming ... and i dnt understand much

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The format string MK27 gave you tells printf to pad zeros onto single digits in a field of 2 columns, so instead of 1 you get 01.

    printf displays anything exactly how you tell it to, so if you neglect to give it a correct format string it will just work however it is programmed to work. You just need to learn how to use printf. Try reading this and this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Re: need help with the programme
    By prakashb in forum C++ Programming
    Replies: 4
    Last Post: 03-16-2011, 08:04 AM
  2. about this programme
    By kasun007 in forum C Programming
    Replies: 1
    Last Post: 03-07-2011, 08:52 PM
  3. clock() problem
    By hugoguan in forum C Programming
    Replies: 8
    Last Post: 11-23-2010, 01:54 PM
  4. help me with ma c programme..
    By eddie19 in forum C Programming
    Replies: 19
    Last Post: 08-12-2009, 07:53 AM
  5. clock() problem
    By Nick_3596 in forum C Programming
    Replies: 5
    Last Post: 11-29-2007, 03:26 AM