CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Change number of spaces printed-out by \t (tab) [CLOSED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
benoitstjean



Joined: 30 Oct 2007
Posts: 605
Location: Ottawa, Ontario, Canada

View user's profile Send private message

Change number of spaces printed-out by \t (tab) [CLOSED]
PostPosted: Mon Feb 16, 2026 11:40 am     Reply with quote

Compiler 5.116

Hello,

I there a way somewhere either in the configuration files of the compiler or the compiler directly that I can specify the number of spaces that get printed-out when the \t option is used inside an fprintf?

I'd like to be able to put leading and trailing spaces in different fprintf()'s by using \t but it prints-out 8 spaces and it's too much. And if I add individual spaces inside the fprintf, I would guess that that uses more ROM space than a single \t?

Makes sense?

Ben


Last edited by benoitstjean on Wed Feb 18, 2026 2:21 pm; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9622
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 16, 2026 2:30 pm     Reply with quote

hmm, historically a 'tab' was 8 spaces. I know some 'editors' you can change 'tab' to be n number of spaces
You should be able to use fprintf to format though, it follows FORTRAN from what I recall. Others will know, me I'm on day 5 of a 'headache from 'that hot place' .
The BASIC I used ,had the nice Print using "......." function/ feature which allowed formatted output,made it easy to get 'stuff' onto the screen all lined up.
newguy



Joined: 24 Jun 2004
Posts: 1929

View user's profile Send private message

PostPosted: Mon Feb 16, 2026 6:25 pm     Reply with quote

I had a look through the project options of one projects but I can't see a setting for a tab equating to a set number of spaces. I suspect it may be hard coded in the compiler. That said, contact CCS directly to ask. Never know, it may be something they can easily accommodate via a command line option or future update in the IDE.

In the meantime, you might be able to accomplish the same thing with a clever define, then do a search & replace in your codebase to substitute a conventional tab with your define.
Ttelmah



Joined: 11 Mar 2010
Posts: 20034

View user's profile Send private message

PostPosted: Tue Feb 17, 2026 1:39 am     Reply with quote

You can make %f print to a fixed width field by specifying a width. So
%8f maxes it use an eight character field. %08f makes it add leading zeros.
However 'caveat', that the field 'width' always includes things like the DP,
and if your number goes over the specified width, the field will expand
to accommodate the number.
jeremiah



Joined: 20 Jul 2010
Posts: 1407

View user's profile Send private message

Re: Change number of spaces printed-out by \t (tab)
PostPosted: Tue Feb 17, 2026 9:23 am     Reply with quote

benoitstjean wrote:
I there a way somewhere either in the configuration files of the compiler or the compiler directly that I can specify the number of spaces that get printed-out when the \t option is used inside an fprintf?


That's not how \t works. The function printf isn't sending out any spaces when you use \t, it's sending out the character \0x09 to the terminal. The receiving terminal then decides how many spaces to put out. printf has no control over that, only receiver / user has control over that by what terminal settings you have. So your only shot when using \t is to go to your terminal's settings and hope they have one for tab width. If they don't, then you can't do much. And if your users use a different terminal, they would have to set it up how they like it.

Ttelmah's suggestion on using the "min width" format specifier is probably your best bet to get what you want.
benoitstjean



Joined: 30 Oct 2007
Posts: 605
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Feb 18, 2026 8:52 am     Reply with quote

Thanks guys.

Unless anyone has another explanation, I guess \t doesn't appear to be anything other than 8 spaces as opposed to let's say on a PC where the tab uses a pre-defined size e.g. In MS Word for instance, adding a tab in front of a word on one line versus padding with spaces in front of a word on the following line will not align vertically the words.

On the PIC, 8 spaces will align with \t.

I guess the only difference is that it's easier to be \t and probably helps using less ROM versus individual spaces.

I'll use spaces.

Thanks,

Ben
jeremiah



Joined: 20 Jul 2010
Posts: 1407

View user's profile Send private message

PostPosted: Wed Feb 18, 2026 11:51 am     Reply with quote

benoitstjean wrote:
Thanks guys.

Unless anyone has another explanation, I guess \t doesn't appear to be anything other than 8 spaces as opposed to let's say on a PC where the tab uses a pre-defined size e.g. In MS Word for instance, adding a tab in front of a word on one line versus padding with spaces in front of a word on the following line will not align vertically the words.

On the PIC, 8 spaces will align with \t.

I guess the only difference is that it's easier to be \t and probably helps using less ROM versus individual spaces.

I'll use spaces.

Thanks,

Ben


I think you missed my post right above yours. \t does NOT get converted to spaces by the compiler nor the PIC. It's purely based on the terminal you use to display. That terminal chooses the number of spaces to display (along with other things like how to interpret line feeds and carriage returns). Your same code will display differently for different terminals if they have different tab settings. No spaces are generated by the code.
benoitstjean



Joined: 30 Oct 2007
Posts: 605
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Feb 18, 2026 11:55 am     Reply with quote

oh geez! Sorry! My mistake!

Ok thanks!

Ben
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group