I am doing some programming using C on UNIX. The thing is, I have been working in both UNIX and Windows for practicing.
I created a Delay fucntion over Windows using DevC++ as a compiler, when I tried over the console, it worked as I expected, I mean it was creating a delay (of one second for example) between each operation.
When I tried this function over UNIX, it didn't get the same results. I would like to know what is happening. Then, I tried a Sleep function from the <unistd.h> library and it did the same. When I tried to do an operation that will be printed in the same line, the delay used between each operation is acummulated and then everything is done. For example;
I have to wait four seconds to get all the expression to be printed in the screen, instead of getting each expresion with a one second delay. I hope somebody can help me out. I will aprecciate any help.
Other thing, I have been using the conio.h library of windows to put some color on the console. What can I used on UNIX? Can anybody give a working example?
That would indeed be flashing "Blue", but not what I think you intend. Yes, you can run the escape codes together, the consoles receive them as a stream anyway.
Basically UNIX is Bufferred system.
It has two types of buffering system.
1) Line Buffering
2) Block Buffering.
The printf() in C uses the Linf Buffering System. It means, first the Strings are moved to a Buffer. After the Buffer moves the strings to console/memory. The Buffer is cleared, when any one of the following scenario occurs.
1) If the Buffer is full
2) new line Char "\n" occurs
3) The Buffer is flushed by fflush()
4) The Program Terminates.
from the porter's Solution
we have to use the fflush to clear the buffer.
and also we have to use "\n" in all the printf().