CodeBlocks - my program crashes on file import (debugging).

This is a discussion on CodeBlocks - my program crashes on file import (debugging). within the C Programming forums, part of the General Programming Boards category; Hi, im using CodeBlocks and have only changed code that follows on from this section. My program runs up to ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    53

    CodeBlocks - my program crashes on file import (debugging).

    Hi, im using CodeBlocks and have only changed code that follows on from this section. My program runs up to a importing all data and some outputs.
    But if i run it in debug mode now. It crashes Codeblocks at file import.

    The code i have.

    Code:
    int main(int argc, char* argv[]) {
    
        GJCType menu;
    
        char stringInput[MENU_INPUT + EXTRA_SPACE];
        int menuSelection = 0;
        char *ptr;
    
        systemInit(&menu);
    
        if (argc == 3) {
            loadData(&menu, argv[1], argv[2]);
        } else {
            fprintf(stderr, "File import incorrect should be menu.dat submenu.dat");
            exit(EXIT_FAILURE);
        }
    Code:
    int loadData(GJCType* menu, char* menuFile, char* submenuFile) {
    
        FILE *menuInput;
        FILE *submenuInput;
        char lineBuffer[MAX_LINE_LENGTH+1];
    
        int validation;
    
        printf("IMPORTING DATA... from Files\n");
        menuInput = fopen(menuFile, "r");  /* Crashes CodeBlocks here */
        submenuInput = fopen(submenuFile, "r");

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Does it run outside the debugger?
    Are you building it with debugging information included?

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    53
    Runs when i do a 'Build and Run' but not with the Debugger.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by TonyG View Post
    Runs when i do a 'Build and Run' but not with the Debugger.
    Ok... so you're doing a debug build?

    Yes.. it matters... release builds are not compatible with the debugger.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    > menuInput = fopen(menuFile, "r"); /* Crashes CodeBlocks here */
    1. You mean the debugger is pointing at this line of code?

    > printf("IMPORTING DATA... from Files\n");
    2. Or are you just IMPLYING that this is the location of the crash, based on the fact that this line is the last line printed?

    Because if it's door number 2, then you need to realise that stdout is buffered, and the program could have gone past where you think it has gotten to before actually crashing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    May 2011
    Posts
    53
    Debugger hangs at the line of code - menuInput = fopen(menuFile, "r"); following the debugger line by line.

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    53
    Any chance that this could be caused by malloc at some point further in my code? Because that was the only thing i messed with before this happened.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well... you could try investigating that... it's usually the last thing you mess with that causes the problems.

    Old technician's adage... "If it ain't broke, don't fix it. If it is broke, know when to stop fixing it."

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    So is the code you posted the ACTUAL code that has run up to that point?

    You see, you mentioned malloc, but there is no malloc in any of the code you posted (how do you know malloc is involved).

    FWIW, abusing malloc can easily cause all kinds of random effects at any later point in the code.

    Which is why we make a noise about whether this is all your code under test, or whether you just edited out all the interesting stuff, and just posted where you thought the problem was.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strtok and CodeBlocks debugging
    By TonyG in forum C Programming
    Replies: 3
    Last Post: 05-15-2011, 02:42 AM
  2. Codeblocks crashes linux?
    By Shakti in forum Tech Board
    Replies: 1
    Last Post: 03-25-2009, 07:26 AM
  3. program crashes when copying binary file
    By bored_guy in forum C Programming
    Replies: 9
    Last Post: 11-21-2008, 02:02 AM
  4. Program crashes on reading a line from a file
    By bluescreen in forum C Programming
    Replies: 5
    Last Post: 10-19-2006, 05:23 AM
  5. counting program worked, but test file CRASHES IT.. WHY?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 05-19-2002, 02:29 AM

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