[LCP]Simple C test

James Mclean james at adam.com.au
Thu Jul 4 16:27:06 UTC 2002


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




More information about the linuxCprogramming mailing list