I want to stop the \t tab after 5 spaces, How do i do that?

Recommended Answers

All 5 Replies

Not sure whether you can do it , but check stty manual.

You could try something like below...I generally don't like the solution but it works for some situations

#include <stdio.h>
#include <stdlib.h>

#define t "     "

int main(int argc, char**argv)
{		
	fprintf(stdout, "this\tis\ta\ttest", stdout);	
	exit(EXIT_SUCCESS);
}

You could try something like below...I

That should produce an error because \' ' is not a valid escape sequence.

If you don't like the default spacing then don't use tabs. Do something like this: printf("%-20s", "Hello World"); where the text string will be left-justified in a field 20 characters wide, right-side padded with spaces.

C doesn't specify tab stops, only tab characters. It's up to the program consuming those characters to interpret the character with a certain tab stop length, just like it's up to the same program to accurately print the 'Q' character. Translation: change the properties of whatever program is displaying those tabs to use a five character tab stop explicitly. Most likely this will be your shell, for command line programs that send output to stdout.

It does not work for me.

It is as the default. I modified it but it does not worked.

Help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.