output will not write to a second file

This is a discussion on output will not write to a second file within the C Programming forums, part of the General Programming Boards category; If someone could help I would greatly appreciate. I am reading in a compressed file, searching for "bad" data, and ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    Unhappy output will not write to a second file

    If someone could help I would greatly appreciate. I am reading in a compressed file, searching for "bad" data, and writing out an error file if any bad data is found. My problem is that the "good" file is writing fine, but i am not able to write to the other file. I noticed that I can get things to print if I loop more than five times.
    I even tried inserting and fprintf command at the very beginning of the program and nothing will write to this file. This is very weird and I have never encountered this before. Does anyone have any ideas? Thanks.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code? We are not mind reader, you know...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685

    Speak for yourself Magos!

    First off you do realize that printf writes to stdout, right? You should be opening your files before you process the file. The reason for this is because it is possible that you are only allowing the file to be open under a condition that is not being met. Also you may be opening it more than once (unlikely though, your problems would be much different). You could also write your errors to stderr. And if you desperately need stderr dumped into a file you can always do this:

    Code:
    FILE *my_error_log = freopen("error.log", "w", stderr);
    
    //the next two statements do the same thing
    fprintf(my_error_log, "error!");
    fprintf(stderr, "error!");
    Of course the skeleton code there omits error handling.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. I'm not THAT good am I?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-19-2006, 10:08 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM

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