Program crashing as windows executable

This is a discussion on Program crashing as windows executable within the C Programming forums, part of the General Programming Boards category; Hi, I made a program about ~4k lines on my university's server with text editor Pico and gcc compiler. It ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    20

    Program crashing as windows executable

    Hi,

    I made a program about ~4k lines on my university's server with text editor Pico and gcc compiler. It works perfectly on their linux based server, but when I e-mail it to myself and then put it in Code Blocks and create the windows executable with MinGW, it crashes fairly quickly.

    I thought it could be a stack overflow problem, but I believe I've successfully adjusted the stack size to 3 gigs (just for testing purposes), and it still fails.

    Would anyone know an alternative to the windows executable? Could I possibly download something similar to what my school is using, so that it doesn't crash?

    I know the details are vague, but that's the extent of what I know as of now. Of course, I could edit down my code, but as of now I'm not interested in trying that. (I'm guessing it wouldn't be just a quick fix.)

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What you need to do is fix your program. "It works over there" doesn't mean your program is correct.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by tabstop View Post
    What you need to do is fix your program. "It works over there" doesn't mean your program is correct.
    Agreed... when it works "both here and there" it stands a much better chance of being correct.

    That said... it might be headers or use of OS specific functions in which case it should be fairly easy to get the most of it corrected with a few #defines...

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    As the previous two posters have stated it's almost certainly a bugged program.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,195
    Quote Originally Posted by porstart View Post
    I know the details are vague, but that's the extent of what I know as of now. Of course, I could edit down my code, but as of now I'm not interested in trying that. (I'm guessing it wouldn't be just a quick fix.)
    The most reliable "quick fix" in these things is "work out the real problem and eliminate the cause". That means you have to do exactly what you are not interested in doing.

    Laziness and reliance on finding some download to cope are not particularly effective problem solving strategies.

    Even in tiny snippets of code like yours.
    Right 98% of the time, and don't care about the other 3%.

  6. #6
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Run it through a debugger and post the lines/code near the lines when it crashes.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Also you've got gdb, so you can run it in the debugger and see where you are when it all goes pear-shaped. (You will have to compile with -g; and if you're just using a single file rather than a project I don't think you get the integrated debugger with C::B but will have to run it from the command line.)

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    20
    Quote Originally Posted by tabstop View Post
    Also you've got gdb, so you can run it in the debugger and see where you are when it all goes pear-shaped. (You will have to compile with -g; and if you're just using a single file rather than a project I don't think you get the integrated debugger with C::B but will have to run it from the command line.)
    I discovered that, but I was waiting to post the error till I had time to work on it myself.

    it's a segfault on this line:

    Code:
     res = strcmp(letters, base[x]);
    the variables involved have these declarations:

    Code:
    //global
    char letters[MAX+1];
    char *base[SIZE];
    int depth;
    
    //local
    static int res, x;
    letters[depth] = '\0';
    I can't see a problem yet.
    Last edited by porstart; 01-22-2011 at 04:16 PM.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    2,507
    Quote Originally Posted by porstart View Post
    Code:
     res = strcmp(letters, base[x]);

    Code:
    //global
    char letters[MAX+1];
    char *base[SIZE];
    int depth;
    
    //local
    static int res, x;
    letters[depth] = '\0';
    I can't see a problem yet.
    Check that x is less than SIZE

    Check that base[x] is not NULL/0.

    Tim S.

  10. #10
    Registered User
    Join Date
    Oct 2010
    Posts
    20
    Quote Originally Posted by stahta01 View Post
    Check that base[x] is not NULL/0.

    Tim S.
    That was it, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  2. Replies: 8
    Last Post: 08-01-2009, 11:07 AM
  3. Replies: 6
    Last Post: 01-01-2007, 06:36 AM
  4. Replies: 2
    Last Post: 12-22-2006, 07:45 PM
  5. Replies: 1
    Last Post: 01-24-2005, 01:07 PM

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