Home Forums C Programming Delete an array on structure

Viewing 0 reply threads
  • Author
    Posts
    • #2111
      glimpse
      Participant

      Dear friends.
      I composed an array on a structure and fill the structures. Then I tried to free it again with the free-function, but I still get an error under Visual Studio.
      How do I do it correctly?

      Here my code for allocating and filling:

      SoilVG=(struct soils*) malloc(pSo->iLayers*sizeof(struct soils));

      for(i=0; iiLayers; i++)
      {
      SoilVG.alpha=pSo->pSWater->fVanGenA;
      SoilVG.Ks=pSo->pSWater->fCondSat;
      SoilVG.n=pSo->pSWater->fVanGenN;
      SoilVG.Theta_r=pSo->pSWater->fContRes;
      SoilVG.Theta_s=pSo->pSWater->fContSat;
      pSo->pSWater=pSo->pSWater->pNext;

      if(pSo->pSWater==NULL)
      break;
      }

      Next is the structure soils:
      struct soils
      {
      floatTheta_r;
      floatTheta_s;
      floatalpha;
      floatn;
      floatKs;
      };

      and then I tried to free SoilVG with
      free(SoilVG);

      Thank you in advance.

Viewing 0 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.