Thread: Strange segmentation fault

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > If caught, I will be expelled.
    Surely that's only a problem if you've already copied it from someone else?
    If yours is original, and can cite first publication, then it's the copiers who are in the frame.

    Sometimes, the threats are empty - http://news.bbc.co.uk/1/hi/education/7434277.stm

    If you've managed to comment out most of the code with /**/, then just delete all that and post a small example which crashes. That should address your concerns.
    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.

  2. #17
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Well, you have an extra { on your code posted. But apart from that i compiled it and tested it. It runs fine. Doesn't give me segmentation faults. It is also highly unlikely you ll have one line 100kb, so that shouldn't be the problem. So somewhere else is the problem?

  3. #18
    Registered User
    Join Date
    May 2006
    Posts
    151
    Are you sure you are not getting a segmentation fault. Then it must be the UNIX environment

    This is just frustrating.

  4. #19
    Registered User
    Join Date
    May 2006
    Posts
    151
    What is a good debugger, I can use which can use?
    Would the debugger also access functions from another code file when called upon?

  5. #20
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Well, I m sure. Tested 2-3 files. Do you get seg fault for every file you test? Seeing again the code, I don't think you should get a seg fault.

    Try replacing scanf() with the one that takes us parameter the file (I think it is sscanf) . Maybe try initializing code[] to '\0' or something. I can't think of anything else and everything should work ok in the first plase.
    Before you do anything, try copying this code in a different file and compiling/running again. Maybe you are missing something between your /* */ (happened many time).

    cheers

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    When I try running the code you gave with a file with more than 100000 characters before a space, I didn't get a segfault, but I got no output either. Make of that what you will.

  7. #22
    Registered User
    Join Date
    May 2006
    Posts
    151
    What is a good debugger, I can use which can use?
    Would the debugger also access functions from another code file when called upon?

  8. #23
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    GDB is a famous one. You use a flag -ggdb when you compile and then you run GDB. Google and find manual. But you need to see how it works, and I don't know how it works with functions from other files etc etc

  9. #24
    Registered User
    Join Date
    May 2006
    Posts
    151
    gdb is too complicated to use when using external files.
    Is there any other good debugger?

  10. #25
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    What do you mean by "too complicated to use when using external files?" gdb is used by many developers all over the world in very complex projects. What are these "external files" of which you speak that are mucking up your life so much?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange segmentation fault
    By Lateralus in forum C Programming
    Replies: 2
    Last Post: 06-10-2005, 09:19 AM
  2. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  3. strange segmentation fault
    By lanzyzhang in forum C Programming
    Replies: 4
    Last Post: 07-19-2004, 08:46 AM
  4. strange segmentation fault error!
    By jayjay in forum Linux Programming
    Replies: 1
    Last Post: 10-20-2003, 03:25 PM