horizontal tab - "\t" - what determines number of spaces?

This is a discussion on horizontal tab - "\t" - what determines number of spaces? within the C Programming forums, part of the General Programming Boards category; When using the horizontal tab - "\t" - what determines number of spaces? - its not defined by ASCII is ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    horizontal tab - "\t" - what determines number of spaces?

    When using the horizontal tab - "\t" - what determines number of spaces? - its not defined by ASCII is it?

    If your program relies on the lenght of a string using "\t", is it not good to use "\t" b/c it varies from machine to machine?

    Also, in a separate but related question, when using Visual C++, you can control how many spaces the "Tab" and "Indent" are. Is it good to use the Tab key to represent a number of spaces in a string literal? From what I can tell from Microsoft Help, the space inserted by the tab key is either converted to a number of spaces or converted to a tab character depending on the setting : Tools | Options | Tabs and you can either select "Insert Spaces" or "Keep Tabs"? Is that how this works?
    Last edited by voltson4; 06-29-2003 at 12:49 PM.

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    if you need to space out your output, use fields, like this

    printf("-10%s-10%s","hi", "hello");

    that will left justify hi and hello in a field of 10. I think that is somethink that might help you.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    7
    thanks anyway,

    I'm not using conversion specifications though.

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    chrismiceli, hes asking why are there x spaces in tab.

    its probally a standard, but some programs cheat and use their own(whats worse is when they refuse to put in a '\t' and keep using ' '!).

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>what determines number of spaces?
    The application doing the display.

    A tab is a single byte, and simply represents an unspecified length of white space.

    As for string literals etc, if you want control over the number of spaces, then output spaces, not tabs.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Tabs were used often when you wanted to easily output something to the console and line it up. Ie:
    Code:
    field	another	cprog	word
    differ	final	they	line
    To line these words up I just used a tab. (Cut and pasted from notepad)

    Tabs usually (keyword: usually) go to the next column divisible by 8 (or the one right after that... i can't remember). So 8 letter words or bigger would disrupt tabbing. Which is why it isn't that popular to use tabs to create spaces.
    Last edited by ygfperson; 06-30-2003 at 12:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program giving errors
    By andy bee in forum C Programming
    Replies: 5
    Last Post: 08-11-2010, 10:38 PM
  2. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM
  3. Number system base M, print numbers N digits wide...
    By biterman in forum C Programming
    Replies: 12
    Last Post: 11-19-2001, 03:31 AM
  4. Perfect number
    By TheSki in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2001, 03:34 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21