Thread: Newline parsing?

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    67

    Newline parsing?

    I'm creating an XML parser (please don't suggest any. The point is, I'm making it myself), and I realized that while using fseek, you scrawl through the exact bytes of a file, but when you fread, 0x0A0D (newline character.. for some reason it's 2 bytes long) gets parsed to 0x0A.. it's very annoying, because the file MIGHT have just had 0x0A (not 0x0A0D) so I can't just add 1 to what I'm fseeking if I encounter a 0x0A in my parsed data, but I can't ignore it because that throws it off. Is there any way around this newline parsing problem?
    got the solution. Open it as a binary file (the default is text). Add a 'b' to the end of your opening mode (e.g. "r" becomes "rb"). You don't need to change anything else
    Last edited by RobotGymnast; 07-11-2008 at 10:31 PM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    read the file in text (not binary) mode.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    how do I do that?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >read the file in text (not binary) mode.
    Wouldn't it be the opposite?

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    yeah it is, but I think I got it.. open it as fopen("rb") instead of ("r")

    edit after testing: yes it works. thank you *edits post to include answer*

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >open it as fopen("rb") instead of ("r")
    Correct.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. draw tree graph of yacc parsing
    By talz13 in forum C Programming
    Replies: 2
    Last Post: 07-23-2006, 01:33 AM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. Parsing for Dummies
    By MisterWonderful in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2004, 05:31 PM
  4. I hate string parsing with a passion
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM
  5. fgets and a bothersome newline char
    By ivandn in forum Linux Programming
    Replies: 1
    Last Post: 11-14-2001, 01:41 PM