Monday, May 24, 2010

How to set the tab settings.?

I want to know how to set the tab settings in C programs. When every i use tab it makes 8 spaces in user screen. Now i am using it to make 5 spaces by using space in for loop under a if condition.





Can anyone please help me.

How to set the tab settings.?
This is actually a tough question. So, when your program prompts for user input, and the user hits the tab key, you get 8 spaces. Yes, this is totally separate from any editor, and may be independent of enviroment variables. I might suggest rethinking your program to get around this problem. Can you read keystrokes instead, and echo output to the screen? If so, you can control how many spaces to spit out for a tab.
Reply:That has nothing to do with the C language. It's an editor setting. If you are using an IDE there should be an options setting that you can configure. If you are using a text editor, it would depend on the editor. What editor are you using?





[edit, additional details]


Still, it has nothing to do with C. When you output a TAB character it's a single ASCII byte that is inserted into an output stream using the "\t" format option or just inserting a 0x09 (ASCII tab). That's as much control as you have in "C". Ask yourself this: how does a single byte (0x09) get turned into 8 spaces (versus 1 or 5 or 8) when read back and displayed on the screen? Answer: it depends on how the software that reads the tab interprets and decides display it. Even if what you are talking about is a character string written to a device, every device - weather that device is a simulted one in a windows environment, an old PC text screen, or a really old ASCII CRT terminal - has software behind it that governs how ASCII codes are interpreted and generated the on the screen. When that software encounters TAB character it's interpreted in a specific way: If the font used is fixed width, it tells the software to convert the TAB into a specific (and configurable) number of spaces. If the font used is variable width, it typically tells the software to move the cursor over to a specific (and configurable) position on the screen before generating the next displayable character. Neither of these are configurable from within 'C', they are only configurable from within the software that is interpreting the TAB character.





I might be able to help more if you provide some more details about your application, including the hardware and system environment.


No comments:

Post a Comment