using fprintf crashed my program

This is a discussion on using fprintf crashed my program within the C Programming forums, part of the General Programming Boards category; Hi so Im wondering when would there be a case when fprintf would crash a program. I didn't create the ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    using fprintf crashed my program

    Hi so Im wondering when would there be a case when fprintf would crash a program. I didn't create the program but I'm trying to debug it. I've been able to use fprintf on other files in the program, but for some reason this one file where im just trying to fprintf helloworld crashes the program. And its able to recongize the

    extern FILE* fpvar;

    so its able to see the pointer to the where i originally created fpvar. but once i put a fprintf it crashes the program

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,420
    You may be observing the effects of undefined behaviour. By the way, it is usually better to use a debugger to debug, rather than scatter debug print statements all over the place.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    can you post the code ?

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    Without any code, I'd say the most likely reason is that fpvar doesn't point to a valid file stream that is open for writing. This could be because
    1. fpvar was never initialized or set to the result of an fopen call
    2. fpvar was opened at some point, but then closed, thus it points to bogus memory that does not describe an open file stream
    3. You have some other memory issue, e.g. buffer overflow, that is scrambling the contents of the fpvar pointer and making it point to memory that doesn't describe an open file stream

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    Well I cant use a debugger that i know of cuz im using jni functions and although this isnt a jni function where im getting the problem the main code is base in java and when i call the jni thats when it crashes.
    I cant really post the code because its companys code im trying to debug but i mean the basic thing is i have

    FILE* fpvar in my main code in C where JAVA does a jni call

    then the rest of my files have
    extern FILE* fpvar;
    and it works for other files but this one where im just diong
    fprintf(fpvar, "helloworld\n");

    it crashes once i open the java program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to execute other program within c program?
    By KoYoungSuk in forum C Programming
    Replies: 7
    Last Post: 06-07-2010, 05:08 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. Auto shutdown of crashed program...
    By phil_drew in forum Windows Programming
    Replies: 1
    Last Post: 04-24-2004, 12:48 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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