Thread: Rate of printing

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    147

    Rate of printing

    We use printf to display output onto the screen. Is it possible to decrease the rate of displaying hte output onto the screen?
    Only by the cross are you saved...

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    What do you mean by 'rate'?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    by rate i mean er.........
    for example,

    printf("I am just testing.");

    Instead oif printing the whole text at once, is it possible to print I, followed by the space, followed by 'a' followed by 'm', and so forth at a controlled pace? Just to make it look cool? To simulate that the text is being typed out?
    Only by the cross are you saved...

  4. #4
    Banned
    Join Date
    May 2003
    Posts
    124

    !

    Yeah, it will look very cool....

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >To simulate that the text is being typed out?
    Yes, use whatever delay function your compiler supports after you print each character:
    Code:
    #include <stdio.h>
    #include <time.h>
    
    /* For a portable EXAMPLE only! Don't use this function in a real program */
    void delay(long s)
    {
        clock_t end = clock() + (clock_t)s;
    
        while (clock() < end)
            ;
    }
    
    int main(void)
    {
        char *p = "I am just testing.";
        char *t = p;
    
        while (*t)
        {
            printf("%c", *t++);
            fflush(stdout);
            delay(200);
        }
    
        printf("\n");
    
        return 0;
    }
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    er......wat do u mean by "do not use this function in a real program"?

    while (*t) actually goes thru each character of the statement?

    wat is fflush(stdout) for?

    and wat is the purpose of the while loop? while (clock() < end)
    Only by the cross are you saved...

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >wat do u mean by "do not use this function in a real program"?
    Just what I said, don't use it. In a multitasking environment, that function is very nasty because it doesn't allow anything else to do anything while it performs its busy wait.

    >while (*t) actually goes thru each character of the statement?
    No, while (*t) specifies that the loop will end when the nul terminator is reached, the test is implicit as while (*t != 0).

    >wat is fflush(stdout) for?
    It makes sure that the output buffer is flushed so that you can actually see the typing effect.

    >and wat is the purpose of the while loop? while (clock() < end)
    It's a busy wait, like the following except more predictable:
    Code:
    int i;
    
    for (i = 0; i < 10000000; i++)
        ;
    p.s. It's spelled w.h.a.t.
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    67

    do they...

    Do they speak english in what?

    [sorry pulp fiction addict]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Producing a "beeep!" as simply as possible
    By mutandis in forum C Programming
    Replies: 10
    Last Post: 12-13-2008, 01:30 AM
  3. Question About My Homework Pls Help Me İmmediately
    By jennyyyy in forum C Programming
    Replies: 27
    Last Post: 03-13-2008, 11:40 AM
  4. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM
  5. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM