Xcode "Tab" problem with C

Discussion in 'Mac Programming' started by pixelpunch, Oct 6, 2008.

  1. pixelpunch macrumors newbie

    pixelpunch

    Joined:
    Sep 8, 2008
    Location:
    canada's wonderland
    #1
    i'm learning C right now (the basics) and for some reason when i put \t to create a tab it works fine but sometimes it won't create a tab and i have to use 2 \t's to create just one tab. i've rechecked the code many times and there isn't anything wrong. the debugger shows no errors as well.

    here's an example of the code i (have to) used:

    Code:
    #include <stdio.h>
    
    int main()
    
    {
    printf ("Sun\tMon\tTue[COLOR="Red"]\t\t[/COLOR]Wed\tThur\tFri[COLOR="red"]\t\t[/COLOR]Sat\n");
    printf ("\t\t\t\t\t1\t\t2\t\t3\n");
    printf ("4\t5\t6\t7\t8\t9\t10\n");
    printf ("11\t12\t13\t14\t15\t16\t17\n");
    printf ("18\t19\t20\t21\t22\t23\t24\n");
    printf ("25\t26\t27\t28\t29\t30\t31\n");
    
    }
    
    you see how i needed to use 2 \t to create just one tab.
    i don't know why certain parts require 2 \t to create just one tab.

    i copied the exact code from the book and it does the same thing but the code from the book only uses 1 \t when needed.
    is it a bug with Xcode?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    How are you checking to see if a tab has been printed or not? It's probably a visual trick. You just can't see where the tab stops are in the output. Since you're using an IDE, you're relying on the provided console, but if you ran this from a terminal and used something like od to look at the output, i'm sure both tabs are there.

    -Lee

    I ran this from a console, and the double tabs show as two tabs, and this causes alignment problems.
     
  3. pixelpunch thread starter macrumors newbie

    pixelpunch

    Joined:
    Sep 8, 2008
    Location:
    canada's wonderland
    #3
    hi, thanks for the quick reply,

    i'm just using the Xcode Debug Console and that's where i'm getting this from.
    i guess i should try it on Terminal.

    i guess it's a bug with Xcode then.

    EDIT:

    haha, i found the problem, it's because i used a different font than Courier. i changed it and the problem is fixed. odd.

    thanks for your help. :)
     

Share This Page