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 7833229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:36:46+00:00 2026-06-02T12:36:46+00:00

I am using Eclipse on a 32-bit Ubuntu virtual machine to work on a

  • 0

I am using Eclipse on a 32-bit Ubuntu virtual machine to work on a project. I have a big problem when trying to implement a structure or just when trying to run a specific function. The function is this one:

int count (matrix m, int v[], int w[], int col) {

    int r=0;
    int j=0;

    while (j < m.length) {
        int k=0;
        bool aux=true;

        while (k < col && aux ){
            if (v[k] == 1) {
                if(m.i[j][k] != w[k])
                    aux=false;
            }
            k++;
        }

        if(aux) r++;
        j++;
    }
    return r;
}

This function receives a matrix (defined below), a vector with ones and zeros (to learn which columns to search, a vector with the values we want to search in those columns and also the number of columns (equal to the length of the vectors and matrix). When it strikes the second “if” it gives me Segmentation Fault (I cannot understand what it is), and I can see that it is not correct to define it that way, but I have tried and tried and I can’t seem to find a way to access the values in the vector. Here follows my struct matrix:

typedef int *ind; 

struct matrix { 
    ind *i;
    int length;
};
typedef struct matrix matrix;

In this structure my matrix has a pointer and the length (number of lines); the pointer goes to a vector of pointers (one pointer for each line) and each one of those pointers go to a vector that is, in fact, my line of the matrix. Here go my functions to add and create an empty matrix:

matrix emptyS(int n, int col) {
matrix m;
int d=0;
m.length=0;
m.i=(ind*) malloc(sizeof(int)*n);
int x;
    for (x=0; x < n; x++)
           {
               *m.i = (int*) malloc(sizeof(int)*col);
           }
while (d<n){
    m.i[d]=NULL;
    d++;
}
return m;
} /*Updated*/

matrix add(matrix m,int v[]){
    m.i[m.length+1]=v;
    m.length++;
    return m;
}

I know this is a very specific question but I have been going crazy changing my functions and cannot seem to be successful.

  • 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-02T12:36:48+00:00Added an answer on June 2, 2026 at 12:36 pm

    Your definition of i is this:

     ind *i;
    

    You have the following definition of ind:

    typedef int* ind;
    

    This means that your definition of i really is this:

    int ** i;
    

    Which is a pointer to a pointer, this means you have to allocated your memory incorrectly.

    m.i=(ind*) malloc(sizeof(int)*n); 
    

    This allocation is only for a int*, but what about the second pointer? You’ve never allocated any memory for it!

    Allocate the rows of the matrix, something like this:

    for (int x = 0; x < nofrows; x++)
       { 
           *m.i = (int*)malloc(sizeof(int)); 
       }
    

    EDIT

    Your code after you do your allocation for your matrix, sets your pointers in the matrix to NULL, essentially leaving all the memory you just allocated dangling, with nothing pointing to it!!

    while (d<n){
        m.i[d]=NULL; <--- LEAVES YOUR MEMORY JUST ALLOCATED FOR ROW d DANGLING.
        d++;
    }
    

    You should not set it to NULL, but instead you should write stuff in your matrix you just allocated memory for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Eclipse Ganymede to create a web application, but the project's currently just
Using Eclipse 3.5 (FlashBuilder), I'm doing a bit of AS3 work. With the in-house
I am using eclipse-rcp-helios-SR1-win32-x86_64 64-bit eclipse running on JDK. I am trying to add
I'm using Eclipse Helios and EGit 0.11.3. I have a project where different branches
Using Eclipse IDE. The line: getClass().getResource(/res/bitmaps/image.png); returns null . I have created the res
When using eclipse on ubuntu, for some reason it crashes/stops responding when loading an
I am using Eclipse 3.2.2 with WebSphere Portlet Factory Designer 6.0.2. I have a
i'm using ECLiPSe programming logic system. i want to implement the yield method for
I am using Eclipse 3.4.1 Build M20080911-1700 I have tried to change the classpath
I have been using eclipse-pdt in conjunction with xdebug and apache without problems, for

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.