| View previous topic :: View next topic |
| Author |
Message |
benoitstjean
Joined: 30 Oct 2007 Posts: 605 Location: Ottawa, Ontario, Canada
|
| Change number of spaces printed-out by \t (tab) [CLOSED] |
Posted: Mon Feb 16, 2026 11:40 am |
|
|
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
|
|
Posted: Mon Feb 16, 2026 2:30 pm |
|
|
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
|
|
Posted: Mon Feb 16, 2026 6:25 pm |
|
|
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
|
|
Posted: Tue Feb 17, 2026 1:39 am |
|
|
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
|
| Re: Change number of spaces printed-out by \t (tab) |
Posted: Tue Feb 17, 2026 9:23 am |
|
|
| 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
|
|
Posted: Wed Feb 18, 2026 8:52 am |
|
|
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
|
|
Posted: Wed Feb 18, 2026 11:51 am |
|
|
| 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
|
|
Posted: Wed Feb 18, 2026 11:55 am |
|
|
oh geez! Sorry! My mistake!
Ok thanks!
Ben |
|
 |
|