Thread: outputting characters one at a time

  1. #1
    Unregistered
    Guest

    outputting characters one at a time

    Is there a way to make this code output to the screen one character at a time instead of all at once?
    Code:
    #include<stdio.h>
    
    void main(void)
      {
        int i,j;
        int array[9][9]=  { ' ',' ',' ',' ','*',' ',' ',' ',' ',
    	                ' ',' ',' ','*','*','*',' ',' ',' ',
                            ' ',' ','*','*','*','*','*',' ',' ',
                            ' ','*','*','*','*','*','*','*',' ',
                            '*','*','*','*','*','*','*','*','*',
                            ' ','*','*','*','*','*','*','*',' ',
                            ' ',' ','*','*','*','*','*',' ',' ',
                            ' ',' ',' ','*','*','*',' ',' ',' ',
                            ' ',' ',' ',' ','*',' ',' ',' ',' ',
    	             };
        for(i=0; i<9; i++)
         {
           for(j=0; j<9; j++)
         {
            printf("%c",array[i][j]);
         }
            printf("\n");
         }
    
     }

  2. #2
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    run a long for loop before printing the character, it should work.

    Code:
           for(j=0; j<9; j++)
         {
             for(int i=0; i<200000; i++);
           printf("%c",array[i][j]);
         }
            printf("\n");
         }
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > void main(void
    No, main returns an int, and you should have
    return 0;
    at the end of the function

    > printf("%c",array[i][j]);
    To ensure you see every character, you need to do this
    Code:
    printf("%c",array[i][j]);
    fflush( stdout );  /* force output of any buffered data */
    because standard out is usually buffered, and output only at each newline.

    > for(int i=0; i<200000; i++);
    At the very least, you will need to keep changing this value every time you change your machine.
    It would be better to use a library function like delay(), sleep() or Sleep() if you have them.

    Failing that, try one of these
    Code:
    #include <time.h>
    
    void sleep_seconds ( long seconds ) {
      clock_t limit, now = clock();
      limit = now + seconds * CLOCKS_PER_SEC;
      while ( limit > now )
        now = clock();
    }
    void sleep_ticks ( long ticks ) {
      clock_t limit, now = clock();
      limit = now + ticks;
      while ( limit > now )
        now = clock();
    }

  4. #4
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    void sleep_ticks ( long ticks )
    what do you mean by ticks? and how long are they?
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > what do you mean by ticks?
    Ticks of the clock.
    Exactly which clock is ticking is implementation specific, but it's usually faster than once per second.
    The clock being read will increment by 1 each tick.

    You would use this function if you wanted to pause for some short period of time which wasn't a multiple of a whole second.

    > and how long are they?
    Your time.h file tells you that there are CLOCKS_PER_SEC of them in one second.

    So, if you wanted to wait for 1/2 a second, it would be
    sleep_ticks ( CLOCKS_PER_SEC/2 );

  6. #6
    Unregistered
    Guest
    Using these loops in this manner... wouldn't that print one line at a time in the array instead of one character at a time?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Determine the closest departure time
    By Kyeong in forum C Programming
    Replies: 9
    Last Post: 10-07-2008, 08:06 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM