# problem with C program



## psycho (May 6, 2010)

Hi. I try to create program that will display equal characters ("=") one by one in interval of 1 second. This is my code:

```
#include <stdio.h>
#include <unistd.h>

int main() {
int x;
for (x=0;x<15;x++) {
                     printf("=");
                     sleep(1);
                                     }
return 0;
                 }
```
Problem is that when I comiple and run this program, I wait 15 seconds, and then suddenly all 15 characters appear at once. That is not effect I want. It should be one by one.

Something interesting is that it works when the line with printf is done like this: (thanks to taz_one)

```
printf("=\n");
```

help me


----------



## crsd (May 6, 2010)

Try adding _fflush(stdout)_ after printf() call. Looks like the output is line-buffered. Check setvbuf(3) as well.


----------



## graudeejs (May 6, 2010)

that's because output is buffered


----------



## psycho (May 6, 2010)

thanks, fflush works !


----------

