#include<iostream>
#include<fstream>
#include<sstream>
#include<stdlib.h>
#include<math.h>
#include<iomanip>

using namespace std;

int main()
{
    int NUM_Object,NUM_Medoid;

    cout<<"How many menus u have?"<<endl;
    cin>>NUM_Object;

    cout<<"How many Medoids(k) do you want?"<<endl;
    cin>>NUM_Medoid;


    ifstream myfile("Nutrient.txt", ios::in);
    int i,j,k,count;
    count = 0;
    float TEMP_num;
    double Object[NUM_Object][5];
    double Medoid[NUM_Medoid][5],Medoid_New[NUM_Medoid][5],SUM_Distance[NUM_Medoid],SUM_Pij[NUM_Medoid],
         SUM_P[NUM_Medoid],SUM_Distance_New[NUM_Medoid],SUM_Pij_New[NUM_Medoid],SUM_P_New[NUM_Medoid];
    long double Distance[NUM_Object][Object]; 

    for(i=0;i<NUM_Object;i++)
    {
        for(j=0;j<NUM_Object;j++)
        {
            Distance[i][j] = 0;
        }
    }
    string line;

   if(myfile.is_open())
    {
        while(myfile >> line)
        {
            i=0;
            while(line[i]!='\0')
            {
                if(line[i]==',')
                {
                    line[i]=' ';
                }
                i++;
            }
            string temp(line);
            istringstream iss(temp);

            string word;
            j=0;
            while(iss >> word)
            {
                TEMP_num = atof(word.c_str());
                Object[count][j] = TEMP_num;
                j++;
            }
            count++;
        }
    }

    for(i=0;i<NUM_Object;i++)
    {
        for(j=0;j<5;j++)
        {
            cout<<Object[i][j]<<" ";
        }
        cout<<endl;
    }


    myfile.close();


}

when i try to declare Distance[NUM_Object][NUM_Object]//(line28) when i run on server, it shows "Segmentation fault (core dumped)" i have no idea whats wrong with my code. Please help.
(NUM_Object = 854)

Recommended Answers

All 3 Replies

idk what did i do but it works now! :)

Line 28

 long double Distance[NUM_Object][Object]; 

You got an error because Object as a variable is defined like this:

 double Object[NUM_Object][5];

You can't define it like that, because you're defining the size of that array, and thus you can't pass as number another array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.