Seg Fault before hitting main()

This is a discussion on Seg Fault before hitting main() within the C Programming forums, part of the General Programming Boards category; hello, i'm writing a program and thus far all i have tried to do is read in a text file, ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    2

    Exclamation Seg Fault before hitting main()

    hello, i'm writing a program and thus far all i have tried to do is read in a text file, parse it using strtok(), and try to add it to a hash_table implementation that was given to me. when i try to run the executable, though I get a segfault. The strange thing is, I have a printf("enter main") as the first line of my main method, but it doesnt even get printed... So I guess I'm segfaulting before even reaching the main method...how is this possible?

    Any help would be appreciated, thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Because you need
    Code:
    printf("enter main\n");
    if you expect to actually see the result. (Or print to stderr, since that prints immediately rather than line-by-line.)

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by cargo8 View Post
    hello, i'm writing a program and thus far all i have tried to do is read in a text file, parse it using strtok(), and try to add it to a hash_table implementation that was given to me. when i try to run the executable, though I get a segfault. The strange thing is, I have a printf("enter main") as the first line of my main method, but it doesnt even get printed... So I guess I'm segfaulting before even reaching the main method...how is this possible?

    Any help would be appreciated, thanks
    Post the part of your code that's giving you trouble, in code tags please.

    My crystal ball is in for a tune up...

  4. #4
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    983
    It's completely impossible to say. You've shown almost no code whatsoever.

    If you don't print a newline at the end of your “enter main” (or fflush(stdout) afterward), it might never get printed after a crash, so that's no guarantee that it's happening before main().

    When you see a crash, your first step should be to use a debugger. Good free debuggers are gdb and valgrind: I recommend valgrind for most uses simply because it can often pinpoint the cause of a problem way before any symptoms are seen.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    2
    thank you, i guess i am reaching main. i can debug from here. It was because i had printf("reach main") instead of "reach main\n"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf seg fault
    By mercuryfrost in forum C Programming
    Replies: 19
    Last Post: 08-20-2009, 01:22 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. unknown seg fault reason.
    By egoveneror2 in forum C Programming
    Replies: 16
    Last Post: 04-15-2008, 02:30 AM
  5. Seg fault
    By Fox101 in forum C Programming
    Replies: 18
    Last Post: 04-09-2008, 04:15 AM

Tags for this Thread


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