Thread: set spaces in Tab.

  1. #1
    nilrac
    Guest

    set spaces in Tab.

    The default spaces of a '/t' on my system is 8 spaces. Is there anyway i can set the number of spaces to a different length?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    i need to write a program that replaces spaces with a tab. the string with the spaces entered must look the same after the program replaces it wz tabs. on my system win2k, '/t' tab which by default is displayed by 8 spaces . question is how do i set the length of the tab to any length i want in the code. thanx
    Last edited by nilrac; 11-13-2002 at 04:04 AM.

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by nilrac
    i need to write a program that replaces spaces with a tab. the string with the spaces entered must look the same after the program replaces it wz tabs. on my system win2k, '/t' tab which by default is displayed by 8 spaces . question is how do i set the length of the tab to any length i want in the code. thanx
    What program do you use to display the information?
    In notepad for example you can't change the length of the tab.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    i run the program in Dos command prompt. ask the user for an input and display the input string again but replace blankspaces wz a tab of 8 spaces or less depending on the number of spaces the user input. maybe i shld put it this way. say i want to write a simple text editor in C, that has a function which allows the user to set the number of spaces in a TAB. this was given as an excerise in a book. i been thinking for an soltion for days ...pls help. thanx
    Last edited by nilrac; 11-13-2002 at 05:49 AM.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    i'm using the command line borland compiler that they give out for free. i'm really sorry for repeating myself, not so good at phrasing my question. anywayz i got this problem frm a book 'C by Discovery' by Froster and Froster. the reason to replace blankspaces wz a tab is too reduce the byte size of the file. in the sample output in the bk . they have Tabs in different length. like this:

    brown_ _ _ _ _ _cow

    brown[ T a b ]cow


    brown_ _ _cow

    brown[TAB]cow

    where _ represent a blankspace.
    and the [ TAB ] is used to illustrate that a TAB is present.
    the first line is entered by the user then the program will display line 2 with the spaces replace.
    i know that '/t' in a printf statement will print out a TAB with 8 spaces in between and is the only way i know how to add a tab in the code. so i am wracking my brains as to how i can duplicate the output. if it is even possible?
    Last edited by nilrac; 11-13-2002 at 05:50 AM.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by nilrac
    i know that '/t' in a printf statement will print out a TAB with 8 spaces in between and is the only way i know how to add a tab in the code. so i am wracking my brains as to how i can duplicate the output. if it is even possible?
    A tab is a single byte. It's up to the editor you're viewing the file in to determine how many "spaces" it is displayed as. It never actually is a space though.

    You can convert multiple spaces to a tab simply but looping through the string, and when you spot 2 spaces in a row, output a tab and then throw away anymore spaces until you get to the next non-space character. If that's what you want to do, that is.

    Does that help?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    Originally posted by Hammer
    A tab is a single byte. It's up to the editor you're viewing the file in to determine how many "spaces" it is displayed as. It never actually is a space though.

    You can convert multiple spaces to a tab simply but looping through the string, and when you spot 2 spaces in a row, output a tab and then throw away anymore spaces until you get to the next non-space character. If that's what you want to do, that is.

    Does that help?
    yes it did help. well, actually i misinterpreted the question. my part to blame . It shld be done ur way ...thanx

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    since \t has 8 spaces in windows.

    what if i want it to have 9 or 10, or even more spaces. can it be done? say if i only run my program in the dos command prompt and not redirected to other text editor or applications.

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>since \t has 8 spaces in windows.
    No. It may look the equivalent of 8 spaces, but thats only because your application settings say so, it has nothing to do with Windows.

    For example, I use Ultra Edit as my text editor. in the setting panel I can customise how many spaces a tab gives.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VIM: The (un)official thread
    By MK27 in forum Programming Book and Product Reviews
    Replies: 32
    Last Post: 04-20-2011, 06:43 PM
  2. How to set a number of decimal spaces?
    By Diablo02 in forum C# Programming
    Replies: 2
    Last Post: 09-26-2007, 02:10 PM
  3. Replies: 4
    Last Post: 10-14-2005, 12:53 PM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM