When you are printing a tab character to the standard output using printf
in C, it outputs some space which is apparently 4 characters in length.
printf("\t");
Is there a way by which I can control the tab width in the above case?
printf simply sends a \t to the output stream (which can be a tty, a file, etc.). It doesn't send a number of spaces.
Characters in the format string are copied to the output or, if a % is encountered, are used to format an item. In addition to the standard formats, %b causes printf to expand backslash escape sequences (for example \n for newline), and %q outputs an item that can be used as shell input.
%3d can be broken down as follows: % means "Print a variable here" 3 means "use at least 3 spaces to display, padding as needed" d means "The variable will be an integer"
The Printf module API details the type conversion flags, among them: %B: convert a boolean argument to the string true or false %b: convert a boolean argument (deprecated; do not use in new programs).
That's something controlled by your terminal, not by printf
.
printf
simply sends a \t
to the output stream (which can be a tty, a file, etc.). It doesn't send a number of spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With