Thread: fprintf not printing newline

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    32

    fprintf not printing newline

    I have searched around and have found that this is a pretty common error, but fprintf isn't printing newline/return carriages.

    Code:
    FILE *index;
    index = fopen("index.html", "w");
    fprintf(index, "Website Information: \n");
    fclose(index);
    I have tried w, w+, wb for the file type.
    I have tried \n, \r, \r\n for the newline/return commands.

    Nothing is working.

    I am running NetBeans on windows, compiling using cygwin.

    Thanks for any help.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    If it's a common problem, what are the common solutions?
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    32
    Quote Originally Posted by oogabooga View Post
    If it's a common problem, what are the common solutions?
    Well, if any of them worked I wouldn't have posted this. The solutions I saw were to try what I mentioned above, i.e. the different file types and the different commands for newline/carriage return.

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    But none of those would change anything. I ran your program and it worked just fine (file ends 0x0D 0x0A). Maybe it's a NetBeans problem?

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    32
    Well it is compiled with Cygwin, NetBeans shouldn't cause this error. And the difference in \r and \n would change things. Linux expects \n, windows \r\n and mac \r, so this could effect things.
    NOTE: I tried writing to index.txt as well, not returning the newline.

  6. #6
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    When opened in text mode on windows printing a \n actually outputs a \r\n, as it did for me. But still, your problem is a strange one.

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    32
    edit: rebooted netbeans, and everything is operational oddly enough.
    Last edited by Brandon Smith; 03-01-2012 at 05:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newline with fprintf()
    By carderne in forum C Programming
    Replies: 3
    Last Post: 09-28-2010, 03:05 PM
  2. Replies: 7
    Last Post: 03-26-2008, 03:21 AM
  3. fprintf in void function Not Printing
    By thetinman in forum C Programming
    Replies: 5
    Last Post: 10-17-2006, 05:13 PM
  4. printing error using fprintf
    By ahming in forum C Programming
    Replies: 7
    Last Post: 05-26-2005, 09:45 PM
  5. formatted printing with fprintf
    By lambs4 in forum C Programming
    Replies: 5
    Last Post: 11-20-2001, 09:04 AM

Tags for this Thread