Thread: An access violation (segmentation fault) raised in program

  1. #1
    Registered User
    Join Date
    Jan 2010

    An access violation (segmentation fault) raised in program

    hello guys

    i wrote a program in dev cpp and when i compile it with 0 warnings or error
    the program doesnt run for me
    in addition when i debug this program it wrote to me:
    "An access violation (segmentation fault) raised in program"

    what is the problem?
    int path(int* b,int n);
    int findmin(int* board,int n);
    #include <stdio.h>
    #include <stdlib.h>
    int main()
           int b[15]={3,4,5,5,6,9,9,8,5,4,7,5,3,1,2};
           int n=5,p;
           return 0;
     int path(int* b,int n)
     int m=0;
     if(n==1){return *b;}
     return (m+path(b-n,n--));
     int findmin(int* board,int n)
              int i=0,min=0;
         return min;

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    How about posting the whole error message.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    A segmentation fault happens when you try to access memory out of your bounds. You have a pointer to an array of 15 integers. If you ever incremented or decremented it so that it no longer pointed inside that array - you would most likely get a segmentation fault.

    Trace through the execution of your code - and see if you can find a situation where you've accidentally allowed your pointer to go out of bounds.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > return (m+path(b-n,n--));
    You've used the post-decrement, so all you've managed to do is

    return (m+path(b-n,n));

    The -- happens, but the result vanishes.

    return (m+path(b-n,n-1));
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. segmentation fault... first time with unix...
    By theMethod in forum C Programming
    Replies: 16
    Last Post: 09-30-2008, 02:01 AM
  2. Strange segmentation fault
    By Ron in forum C Programming
    Replies: 24
    Last Post: 06-15-2008, 02:10 PM
  3. Access Violation?
    By rwmarsh in forum C++ Programming
    Replies: 6
    Last Post: 05-04-2006, 10:56 AM
  4. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  5. Segmentation fault in beginning or program
    By tameeyore in forum C Programming
    Replies: 1
    Last Post: 02-26-2005, 08:16 PM

Tags for this Thread