Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printf \t option

Tags:

c

printf

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?

like image 311
liv2hak Avatar asked Jul 11 '11 05:07

liv2hak


People also ask

What does \t do in 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.

What is %q in printf?

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.

What does %3f mean in C?

%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"

What is %B in printf?

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).


1 Answers

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.

like image 51
cnicutar Avatar answered Oct 04 '22 06:10

cnicutar