Thread: Newline characters

  1. #1
    Frustrated C Programmer
    Join Date
    Sep 2005

    Newline characters

    Recently, I've been working with taking input from files and putting the output into another file. The problem I've been having is that when I put a newline character into a file using the fputc statement, it just prints a square box (the visible representation of the newline character, I guess?) instead of a new line. Here's a little snippet of what I'm doing that causes this.

    fputc('\n', ofp);
    It does the same thing with the fprintf statement.

    Any ideas as to why it won't just start a new line instead of putting a square box there?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    It doesn't put a box. That's the fault of whatever you're using to view your file.

    Hope is the first step on the road to disappointment.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    If you're in Windows then try this instead:
    fputc('\r', ofp);
    fputc('\n', ofp);
    Just add the line that sticks the '\r' in there before the line that sticks the '\n' in there.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Super Moderator Harbinger's Avatar
    Join Date
    Nov 2004
    If you open the file in text mode (on a windows machine), then \r should be stripped when you read it, you'll only see \n and it will be added when you print a \n (\r\n appears in the file).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 06:05 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM