Please help me - thesis

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twinmale
    New Member
    • Nov 2006
    • 1

    Please help me - thesis

    Hi,
    I'm doing quite a simple thing which is giving me problems. I m allocating memory for a 3dimensional array as the following:


    double ***alloc()
    {
    double ***tp;
    int x;
    long t;
    tp=(double ***)calloc(maxt ,sizeof(double **));
    for(t=0;x<=maxt ;t++)
    tp[t]=(double **)calloc(maxx+ 1,sizeof(double *));

    for(t=0;t<=maxt ;t++)
    for(x=0;x<=maxx +1;x++)
    tp[t][x]=(double *)calloc(maxy+1 ,sizeof(double) );
    return tp;
    }


    however when i call this function, the program exits and does not execute the rest of the commands in the main().

    PLease have anyone ecountered such a problem?

    I m using lcc-win as a compiler,

    regards

    alan
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by twinmale
    Hi,
    I'm doing quite a simple thing which is giving me problems. I m allocating memory for a 3dimensional array as the following:


    double ***alloc()
    {
    double ***tp;
    int x;
    long t;
    tp=(double ***)calloc(maxt ,sizeof(double **));
    for(t=0;x<=maxt ;t++)
    tp[t]=(double **)calloc(maxx+ 1,sizeof(double *));

    for(t=0;t<=maxt ;t++)
    for(x=0;x<=maxx +1;x++)
    tp[t][x]=(double *)calloc(maxy+1 ,sizeof(double) );
    return tp;
    }


    however when i call this function, the program exits and does not execute the rest of the commands in the main().

    PLease have anyone ecountered such a problem?

    I m using lcc-win as a compiler,

    regards

    alan
    tp is a local variable the value of which is lost when the function returns. Either pass in it to the function as a parameter from main(), define it as static or make it global

    Comment

    • sivadhas2006
      New Member
      • Nov 2006
      • 142

      #3
      Originally posted by twinmale
      Hi,
      I'm doing quite a simple thing which is giving me problems. I m allocating memory for a 3dimensional array as the following:


      double ***alloc()
      {
      double ***tp;
      int x;
      long t;
      tp=(double ***)calloc(maxt ,sizeof(double **));
      for(t=0;x<=maxt ;t++)
      tp[t]=(double **)calloc(maxx+ 1,sizeof(double *));

      for(t=0;t<=maxt ;t++)
      for(x=0;x<=maxx +1;x++)
      tp[t][x]=(double *)calloc(maxy+1 ,sizeof(double) );
      return tp;
      }


      however when i call this function, the program exits and does not execute the rest of the commands in the main().

      PLease have anyone ecountered such a problem?

      I m using lcc-win as a compiler,

      regards

      alan
      Hi Alan,

      Can you post your full code?
      It will be useful to identify the problem very easily.

      Regards,
      M.Sivadhas.

      Comment

      Working...