First-chance exception in data_generation.exe: 0xC0000005: Access Violation.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ritvik
    New Member
    • May 2007
    • 8

    First-chance exception in data_generation.exe: 0xC0000005: Access Violation.

    hi all
    can anyone please help me with this error.code was working properly earlier giving appropritae results before addign the functions :
    assign_ordersiz e();
    user_data.print odsize();

    this is my code :
    #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    //using namespace std;

    class data
    {
    int Machno,Lotn;
    int *lots,*wl;
    int **ordersinM;
    //int *wl;
    int *JM;
    int totalotsz;
    int totalodsz;

    public:
    void initvalues()
    {
    int i;
    cout<<"Enter the number of lots being processed";
    cin>>Lotn;
    cout<<"Enter the number of EDS lines in the system";
    cin>>Machno;
    JM = (int *) malloc(Machno);

    for(i=0;i<Machn o;i++) {
    cout<<"Order for line "<<i;
    cin>>JM[i]; }
    }
    int getnoflots()
    {
    return Lotn;
    }
    void ass_lotsize()
    {
    int i,temp;
    totalotsz=0;
    wl = (int*) malloc(Lotn);
    srand(time(NULL ));

    for(i=0;i<Lotn; i++) {
    //do {
    temp = rand()%10 * 5;
    //}while(temp!=0) ;

    wl[i] = temp;
    totalotsz=+temp ;}
    cout<<"totallot size : "<<totalots z;
    }
    int maxJM()
    {
    int max = 0;
    int i;

    for(i=0;i<Machn o;i++)
    if(JM[i] > max)
    max = JM[i];
    return max;
    }



    int * accesslotsize() {
    return wl;
    }

    void assign_ordersiz e()
    {
    int i,j;
    int temp;
    totalodsz=0;
    ordersinM = (int **)malloc(Machn o*maxJM()*sizeo f(int));
    for(i=0;i<Machn o;i++)
    {
    for(j=0;j<maxJM ();j++)
    {
    //do {
    temp = rand()%100;
    //}while(temp!=0) ; */

    ordersinM[i][j]=temp;
    totalodsz =+ temp;
    }
    }
    cout<<"total order for all the lines "<<totalods z;
    }

    void printodsize()
    {
    int i,j;

    cout<<"Order size generated are :"<<endl;
    for(i=0;i<Machn o;i++)
    {
    for(j=0;j<maxJM ();j++)
    {
    cout<<"line "<<i<<" order "<<j<<" : "<<ordersin M[i][j];
    cout<<endl;
    }
    }
    }


    };


    void main()
    {
    class data user_data;
    int *uwl;
    int i, temp,limit;

    user_data.initv alues();
    cout<<"these are the lot sizes"<<endl;
    user_data.ass_l otsize();
    uwl = user_data.acces slotsize();
    limit = user_data.getno flots();

    for(i=0;i<limit ;i++)
    cout<<uwl[i]<<endl;

    user_data.assig n_ordersize();
    cout<<"i m not reading this";
    user_data.print odsize();

    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Hi,
    You are not allocating memory for the second dimension array in the code...
    [CODE]
    ordersinM = (int **)malloc(Machn o*maxJM()*sizeo f(int));
    for(i=0;i<Machn o;i++)
    {
    for(j=0;j<maxJM ();j++)
    {
    //do {
    temp = rand()%100;
    //}while(temp!=0) ; */

    //ordersinM[i][j]=temp; // Issue is here
    //Allocate memory for ordersinM[i][j] first and store the value....
    totalodsz =+ temp;
    }
    }
    [CODE]

    Thanks
    Raghuram

    Comment

    Working...