[LCP]Simple C test

Andrew Weaver Andrew.Weaver at tecnomen.fi
Thu Jul 4 16:55:06 UTC 2002


It does what you want. The problem is just that since stdout is buffered,
you don't see the output. Add fflush(stdout) between your printf and sleep.

On Thursday, July 04, 2002 9:31 AM, James Mclean [SMTP:james at adam.com.au]
wrote:
> 
> All,
> 
> I have written a small program to test out the \r carrige return.
> Perhaps i am missing the point, but it is not working as i would have
> thought.
> 
> This code below is used to count to 20, but in the one spot, rather then
> spaces between each line or on a new line.
> 
> if i use a \n rather than a \r it puts it on a new line, one at a time.
> what i want to see is each number ans it is incremented up to 20, rather
> than just 20, once it finishes its loop.
> 
> #include <stdio.h>
> #include <unistd.h>
> 
> int main(void) {
> 
>     int i;
> 
>     printf("\n");
> 
>     for(i = 1; i < 21; i++ ) {
>         printf("%d\r",i);
>         sleep(1);
>     }
> 
>     printf("\n");
> 
>     return 0;
> }
> 
> mabey i am missing something?
> 
> 
> 
> Regards,
> 
> James Mclean
> 
> "Increased knowledge will help you now.  
>  Have a mate's phone bugged."
> 		-- /usr/games/fortune
> 
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List




More information about the linuxCprogramming mailing list