decfsl decfsl - 4 months ago 8
C Question

Why the first \t doesn't work?

#include "stdio.h"
int main()
{
int toes = 10;
printf("toes=%d\t2toes=%d\ttoes2=%d\n",toes,toes+toes,toes*toes);
return 0;
}


//This is an exercise from c primer plus. After compiling and running, only the second \t works.

Answer

It works fine for me. (example)

Output:

toes=10 2toes=20        toes2=100

Note that \t means "tabulate", or in other words to pad to the nearest multiple of N position, where N is usually 8.

toes=10 takes up 7 characters, so to reach the next multiple of 8 would require printing 1 space.

Comments