Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8328045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:18:58+00:00 2026-06-09T01:18:58+00:00

I have a segmentation fault and would like to know where is my mistake.

  • 0

I have a segmentation fault and would like to know where is my mistake.

Let me explain.

In my main, I declare a 3D array: int*** Matricegroupegeneralisant

Then this main uses a function recuperationinfoFich(&matricegroupegeneralisant);
This function is declared as : recuperationinfoFich(int* * * * matricegroupegeneralisant)

This function recuperationinfoFich uses another function recuperationmatricegroupesgeneralisants(matricegroupegeneralisantA[Ni]);
This function is declared as recuperationmatricegroupesgeneralisants( int*** matricegroupegeneralisant)

My code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void allocationdynamiquetableautroisdimdentier(int**** Matrice,int nbniveau, int nbligne, int nbcolonne)
{
int i,j;
    *Matrice=(int***) malloc (sizeof(int**)*nbniveau);
    for (i=0; i<nbniveau; i++)
    {
        (*(Matrice))[i]=(int**) malloc (sizeof(int*)*nbligne);  // allocation dynamique de la matrice Matrice
        for (j=0; j<nbligne; j++)
        {
            ((*(Matrice))[i])[j]=(int*) malloc (sizeof(int)*nbcolonne);
        } 
    }
}


void recuperationmatricegroupesgeneralisants(int*** matricegroupegeneralisantA)
{
    (*matricegroupegeneralisantA)[0][1]=1;
}

void recuperationinfoFich(int**** matricegroupegeneralisantA)
{
    allocationdynamiquetableautroisdimdentier(matricegroupegeneralisantA,3, 3, 7);
    recuperationmatricegroupesgeneralisants(matricegroupegeneralisantA[1]);
}



void main(int args, char **argv)
{

    int*** matricegroupegeneralisantA;

    recuperationinfoFich(&matricegroupegeneralisantA);
}

With Gdb :

(gdb) r
Starting program: /home/larimsna1/Desktop/a.out 

Breakpoint 1, 0x000000000040061a in main ()
(gdb) n
Single stepping until exit from function main,
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
0x00000000004005c8 in recuperationmatricegroupesgeneralisants ()
(gdb) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:19:00+00:00Added an answer on June 9, 2026 at 1:19 am

    I suspect the problem has something to do with your allocation function. That being said, there are numerous functional and stylistic issues with the code you provided. In one place, you failed to dereference a pointer enough times, causing you to assign an integer to a pointer type. You needlessly use pointers for most of your transactions when you could simply not pass an argument and use a return value.

    This code should do what you want, and should work properly, and is easier to read:

    // allocation, returns pointer to allocated value
    int *** allocationdynamique(int nbniveau, int nbligne, int nbcolonne)
    {
        int *** Matrice;
        int i, j;
        Matrice = (int ***) malloc (sizeof(*Matrice) * nbniveau);
        for (i = 0; i < nbniveau; ++i)
        {
            Matrice[i] = (int **) malloc (sizeof(**Matrice) * nbligne);
            for (j = 0; j < nbligne; ++j)
            {
                Matrice[i][j] = (int *) malloc (sizeof(***Matrice) * nbcolonne);
            } 
        }
        return Matrice;
    }
    
    // computation, takes 2D array, modifies in place
    void recuperationmatrice(int** matrice)
    {
        matrice[0][1] = 1;
    }
    
    // you shouldn't use void main, its not part of the standard
    int main(int args, char **argv)
    {
        int*** matrice = allocationdynamique(3, 3, 7);
        recuperationmatrice(matrice[1]);
    
        return 0; 
    }
    

    Also, from a stylistic perspective, your variable names are ridiculously long, and you should use spaces around operators.

    A lot of the mistakes in this code are mistakes the compiler is capable of detecting and warning you about. They are valid C code that will compile properly, but in this and most other cases are written in error and will not work as intended. You should compile with compiler warnings to weed out possible accidents:

    gcc -Wall -c file.c -o file.o
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of structs I would like to write to a binary
I have segmentation fault problem with my multiple class files project. Without making empty
I have a segmentation fault in the code below, but after I changed it
I am getting a segmentation fault and I cannot figure out why. I have
I have this output when trying to debug Program received signal SIGSEGV, Segmentation fault
I have a qApp that generates a segmentation fault only when a breakpoint is
launch 1 Segmentation fault ** Don't have a product spec for: 'full' ** Do
I have an array of structs, each of which describes what I would call
I have a segmentation fault 11 error when I run the following code. The
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.