a question on 'printf'

This is a discussion on a question on 'printf' within the C Programming forums, part of the General Programming Boards category; Hi, everyone! I've a simple question on 'printf' function. See the code below: Code: #include <stdio.h> int main (void) { ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    16

    a question on 'printf'

    Hi, everyone!

    I've a simple question on 'printf' function. See the code below:

    Code:
    #include <stdio.h>
    int main (void) {
      printf("this \n");
      printf("confused me\n"); // a breakpoint is set here.
      return 0;
    }
    After compiling the code, I set a breakpoint (see above) in GDB.

    As expected, "this \n" is printed if the execution reaches the breakpoint.

    If I remove '\n' in "this \n" and run the code as above. "this " will NOT be printed if the execution reaches the breakpoint.

    So, this confused me a lot! Any help are highly appreciated! Thank you!

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Question 12.4
    Probably stdout is line buffered. google setvbuf and read the manual yourself.
    http://www.cplusplus.com/reference/c...stdio/setvbuf/
    Last edited by Bayint Naung; 12-12-2010 at 07:50 AM.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    16
    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help again!!
    By ewic0190 in forum C Programming
    Replies: 1
    Last Post: 03-19-2010, 06:56 PM
  2. saying hello and 1st question
    By darksys in forum C Programming
    Replies: 12
    Last Post: 10-31-2008, 02:58 PM
  3. fgets question
    By Ash1981 in forum C Programming
    Replies: 12
    Last Post: 01-12-2006, 08:53 AM
  4. whats wrong with this?
    By petedee in forum C Programming
    Replies: 32
    Last Post: 01-06-2004, 09:28 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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