Thread: Help with printf formatting

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Help with printf formatting

    Hi guys, first time posting.
    I was reading over some code and I need help identifying what the following snippet means:

    Code:
     
    char ack_buf [599];
    printf("\033[2K\r%s\n", ack_buf);
    I don't understand what the "\033[2k" does. I've tried googling for quite a while but all the explanations pertaining to these characters seemed irrelevant and did not make sense to me.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    These are escape sequences interpreted by the terminal. Those sequences allow to move the cursor, change colors, clear the screen, etc. Google 'terminal escape sequence' and you will get your answer for the meaning of 2K in particular. Notice this has nothing to do with C programming.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    See for example

    It looks like "ESC [ 2 K" clears the entire line, as if you'd positioned the cursor at the beginning of the line and overwritten it with all spaces.
    Last edited by dwks; 04-07-2009 at 12:54 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    2
    Ah thank you very much! I will go look that up immediately. I apologize for my inexperience; I was not aware of these terminal escape sequences.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  4. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM