Tabs as Characters

This is a discussion on Tabs as Characters within the C++ Programming forums, part of the General Programming Boards category; I was looking over a program this morning, and I noticed a tab '\t' was assigned to a char variable ...

  1. #1
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256

    Tabs as Characters

    I was looking over a program this morning, and I noticed a tab '\t' was assigned to a char variable and it got me thinking. How can a tab be a character when it consistis of many 'spaces' which are characters?
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Tab is not really a "character" as much as it is a command for formatting. You'll notice that tabs are set to all different sizes depending on what program is processing the text file. The "tab" is represented as a character, because this and many other formatting commands are represented in text files as ASCII numbers. A "char" in C++ is a variable that can hold any of these numbers and thus their corresponding symbol. IT can hold the alphabet, upper or lower case, the numbers, common symbols, and of course, formatting commands. I can't think of a better way to send the format commands.

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    a tab isn't really many spaces... a tab is a tab... many spaces can sometimes be considered equivalent, but in reality it's not. a tab is a blank amount of space used for formatting. unless your text editor converts tabs to spaces, when you send a \b (backspace), it should delete the tab, not 1/5 (or however many spaces) of it. also, it reacts differently. tabs are usually set (sometimes at every half-inch), and sometimes padded on the left so that your output would look like this:

    Code:
    hello    123456
    hi       123456
    whereas spaces would look like this:
    Code:
    hello    123456
    hi    123456
    here is a useful list of escape sequences, most of which you'll likely use at one time or another.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    Oooook.
    Alright major_small, i got it now, it all makes sense. Very good job at explaning it too. Cheers
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by jrahhali
    Oooook.
    Alright major_small, i got it now, it all makes sense. Very good job at explaning it too. Cheers
    really? I looked back at that and realized how bad it really came out...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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