Newline characters

This is a discussion on Newline characters within the C Programming forums, part of the General Programming Boards category; Recently, I've been working with taking input from files and putting the output into another file. The problem I've been ...

  1. #1
    Frustrated C Programmer
    Join Date
    Sep 2005
    Location
    Florida
    Posts
    5

    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.

    Code:
    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
    Posts
    14,826
    It doesn't put a box. That's the fault of whatever you're using to view your file.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    If you're in Windows then try this instead:
    Code:
    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
    Posts
    74
    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, 11:39 PM
  2. Replies: 10
    Last Post: 07-10-2008, 04: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, 07:05 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05: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

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