Thread: segmentation fault

  1. #16
    Registered User
    Join Date
    Nov 2012
    Posts
    16
    i fixed it. i simply had to add
    Code:
    void *__gxx_personality_v0;
    to the code.

  2. #17
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Then don't initialize it. Assuming the compiler likes char input[length+1];. Be sure after the bottom if your loop, before the printf, you put input[i] = '\0';. All strings must have terminating null.

  3. #18
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Okay, try
    Code:
    gcc -Wall -std=c99 main.c
    Then, if that doesn't work, post your exact code, so we can try compiling and toying with it. Also, it might help if you gave us your gcc version. Though unlikely, it may be a bit outdated, or have a known bug.

  4. #19
    Registered User
    Join Date
    Nov 2012
    Posts
    16
    also, i already posted all the source code in the first post

  5. #20
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I just saw that you "fixed" it (your replied while I was writing my reply), but really, declaring that variable to shut the compiler up is a hack, not a fix. There is something strange about how your code is being compiled. For example, file names in Linux are case sensitive, so if it was .C (uppercase) instead of .c, gcc would assume it's C++, and try to compile it as such.

    Also, provide the exact command you used to compile it. By exact, I mean copy and paste it from your terminal or IDE. You may have done that in post #15, or you may have simply looked at the command and retyped it by hand, omitting something critical like an uppercase .C extension.

    Also, I know you posted your code in the first post, but you changed it since then, possibly you changed several things. That means we don't know the exact state of your current code, so we can't exactly replicate your problem, and it's hard for us to fix it.

    I'm just trying to be thorough, and help you solve your problem, not sweep it under the rug.

  6. #21
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Perhaps the input file (and buffer) are too big to be stacked. How about try
    Code:
    char *input;
    ... determine size needed ...
    input = malloc(length + 1); /* dynamically allocate memory */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Getting Segmentation fault
    By godofdoom in forum C Programming
    Replies: 6
    Last Post: 12-21-2010, 02:09 PM
  2. Segmentation fault
    By browser in forum C Programming
    Replies: 8
    Last Post: 12-07-2010, 03:13 PM
  3. Segmentation Fault
    By Dansas in forum C Programming
    Replies: 3
    Last Post: 11-21-2008, 02:12 PM
  4. segmentation fault
    By pshirishreddy in forum C Programming
    Replies: 3
    Last Post: 11-08-2008, 02:46 AM
  5. segmentation fault and memory fault
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 04-02-2002, 11:09 PM

Tags for this Thread