We use printf to display output onto the screen. Is it possible to decrease the rate of displaying hte output onto the screen?
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...
What do you mean by 'rate'?
My best code is written with the delete key.
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...
Yeah, it will look very cool....
>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.
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...
>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:
p.s. It's spelled w.h.a.t.Code:int i; for (i = 0; i < 10000000; i++) ;
My best code is written with the delete key.
Do they speak english in what?
[sorry pulp fiction addict]