fprintf() causes core dump when executed in certain sections of code

This is a discussion on fprintf() causes core dump when executed in certain sections of code within the C Programming forums, part of the General Programming Boards category; I use fprintf() calls throughout a particular function. Most of them cause no problems & behave as expected. However, I've ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    25

    fprintf() causes core dump when executed in certain sections of code

    I use fprintf() calls throughout a particular function. Most of them cause no problems & behave as expected. However, I've just added a conditional statement within this function, and any fprintf() statement I attempt to execute within this conditional statement, causes a core dump when the code runs.

    I've verified that the values & the file pointers within this new conditional statement are all valid. I don't use fclose() on any file pointers until after this condition executes. Any thoughts about what might result in fprintf() calls in only one particular section in the middle of my code, to fail?

    Thanks for your input.

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    25
    In case it's useful: the new conditional statement that's causing problems, was copied verbatim from an earlier code version that ran perfectly. I was careful to declare all variables & file pointers used in this conditional, within my new code. But, although the fprintf() calls worked fine in my previous code, now they're causing a problem...

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    The file pointer is invalid? Who knows without seeing code? Try running it in the debugger.

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    25
    No, as I mentioned, the file pointers that I've tried are all valid (i.e. they can all be used successfully before & after this new conditional, but not within it). But thanks for the suggestion.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    25
    You were right, rags... I had missed that fclose() was being called and *then* the conditional statement had been executing a second time. Problem solved, thanks for the suggestion.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked list program dumping core when executed.
    By V17 in forum C Programming
    Replies: 6
    Last Post: 09-03-2011, 02:14 PM
  2. Why core dump??
    By noodle24 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2006, 04:04 PM
  3. Core Dump in While()
    By KrepNatas in forum C Programming
    Replies: 5
    Last Post: 05-17-2005, 11:15 AM
  4. core dump
    By kermit in forum Linux Programming
    Replies: 0
    Last Post: 08-03-2004, 06:25 PM
  5. core dump
    By lonbgeach in forum C Programming
    Replies: 1
    Last Post: 04-07-2003, 03:34 PM

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