\n problem

This is a discussion on \n problem within the C Programming forums, part of the General Programming Boards category; I have a program that is supposed to add a '\n' to move down to the next line. However when ...

  1. #1
    Registered User
    Join Date
    Dec 2004

    \n problem

    I have a program that is supposed to add a '\n' to move down to the next line. However when I open the file that this is output to I see a square box where the new line should be. Why is this? And is there an alternative char I can use instead of \n for a new line?

  2. #2
    Registered User
    Join Date
    Aug 2005
    For people to be able to help you, you will need to post the actual code that you are having problems with.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It probably means you used feof() in your control loop, and now you have (char)EOF stored in your file.

    Read the FAQ on why feof() is bad in loops.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    Windows is very picky (stupid) about newlines. Try placing \r\n instead of just \n.

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    A '\n' in C is really translated behind the scenes as mentioned above into a \r\n <control return line feed> on Windows. Your problem is the same that I can get a lot looking at textfiles made on a *nix system, where only \n's are used and all the newlines are little <unknown char> boxes. If you are only doing regular fopen with a "w" then the \n is translated behind the scenes, but with binary file I/O ("wb") then you will need to actually write the \r\n, along with things like WriteFile.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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