Thread: So...my program works with a certain input file but not another with the same content

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    19

    So...my program works with a certain input file but not another with the same content

    ...not entirely sure...

    I have a program which takes in a text file and processes what's in there etc. It's the text file I've used with all my tests, I've edited it to test whatever circumstances etc.

    So I made a copy of this file by copying and pasting the contents into blank text file... so basically I now have two text files exactly the same.


    ...except on the first text file it does what it should. On the second text file it...just doesn't. Completely the opposite in fact.

    I'm really REALLY confused. What the hell happened?!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Does one of them end in a newline and the other does not? Read them both a byte at a time until you hit EOF on one of them and see what's left in the other one.

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

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    19
    Does copying and pasting put a different character code at the ends of lines or something? like '\0' instead of '\n'?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well it depends. Copy and paste this:
    ---
    hello world
    ---
    Now, did you end at the end of the last --- line, or did you end at the start of the line with the word 'Now' on it? There's a newline in there some place. Did you happen to include it or not? Which one of those was "right"? That sort of thing.

    Depending on how you've elected to read from the file, having or not having a newline may make the difference in if your program does what you expect.


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

  5. #5
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    I would try placing the cursor after the last character of the faulty file and placing a newline manually. I regularly process a bunch of text files which I cut and paste into one file for convenience and I have to make sure to insert a newline after each paste or it doesn't work. I'm sure that's your problem too.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    19
    I figured it out. It was just putting carriage returns ('\r') at the end of each line rather than '\n'

    Rather annoying.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Different strokes for different folks. Newline - Wikipedia, the free encyclopedia


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

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. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. About the Morse code Converter
    By Amber_liam in forum C Programming
    Replies: 17
    Last Post: 05-29-2002, 08:35 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM