Archive for the ‘I/O’ Category

Stream buffering

The following program doesn’t "seem" to print "hello-out". What is
the reason behind it?

#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
[...]

Continue Reading..
Posted in Embedded Systems Programming, Exceptions and error handling, I/O, Miscellaneous

Dynamic width and precision in printf

Consider this statement:
printf("String: %9.8s", str);
Have you ever used printf in the form show above? Do you know how the printf formats this? If no, then read on…
In %9.8s above, 9 specifies minimum width and 8 specifies the precision. Instead of giving absolute numbers, you can use an asterisk, *.
The field width may also be specified by an [...]

Continue Reading..
Posted in Uncategorized