A Problem in Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sureshk
    New Member
    • Oct 2006
    • 7

    A Problem in Program

    Plase look at this programme.

    int i=0;
    while(i<30){
    if(i==20)
    continue;
    prinf("%d ",i++);
    }

    As for the programme the i value should be print upto 19 and then it will have to be in an infinite loop, but this programme dosen't prints any value. why?
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Originally posted by sureshk
    Plase look at this programme.

    int i=0;
    while(i<30){
    if(i==20)
    continue;
    prinf("%d ",i++);
    }

    As for the programme the i value should be print upto 19 and then it will have to be in an infinite loop, but this programme dosen't prints any value. why?
    Replace

    Code:
    printf("%d ",i++);
    by

    Code:
    printf("%d\n",i++);
    to flush the output buffer and your program will work as desired.

    Comment

    • sureshk
      New Member
      • Oct 2006
      • 7

      #3
      why it is not flushing the output buffer when we are giving the printf statement.

      Comment

      • arne
        Recognized Expert Contributor
        • Oct 2006
        • 315

        #4
        Originally posted by sureshk
        why it is not flushing the output buffer when we are giving the printf statement.
        Since you may want to add more output to the same line. That's why it's waiting for a '\n'. Alternatively, you can flush the output buffer with

        Code:
        printf("%d ",i++);
        fflush( stdout );

        Comment

        • sureshk
          New Member
          • Oct 2006
          • 7

          #5
          Thank you verymuch..

          Comment

          Working...