Link to home
Start Free TrialLog in
Avatar of tiagrajah
tiagrajah

asked on

Reading a large number of floating point data into a dynamically allocated 2 dimensional variable

I wrote a very very simple program to write 40000*84 floating point data into a file and then try to retrieve it back into a 2 dimensional dynamically allocated variable.

#include <stdlib.h>
#include <stdio.h>
#define TOTAL_TRAIN     40000
#define TOTAL_FEATURE     84

void main()
{
     FILE* ftest;
     ftest=fopen  
        ("C:\\windows\\desktop\\train.txt","w");
     if(ftest==NULL)     exit(0);
     
     float num=0.0;
     for(long i=0; i<(TOTAL_TRAIN*TOTAL_FEATURE); i++)
     {
          num=num+1.2;
          fprintf(ftest,"%f\n",num);
     }
     fclose(ftest);
     printf("file write done");
     
     FILE* fsort;
     long total=TOTAL_TRAIN;
     fsort=fopen
        ("C:\\windows\\desktop\\train.txt","r");
     if(fsort==NULL)     exit(0);
     
     float** features=new float* [TOTAL_TRAIN];
     for(i=0; i<TOTAL_TRAIN; i++)
          features[i]=new float [TOTAL_FEATURE];
     
     for(i=0; i<TOTAL_TRAIN; i++)
     {
          printf("%d\n",i);
          for(int j=0; j<TOTAL_FEATURE; j++)
          {              
          fscanf(fsort,"%f",&features[j][i]);
          }
     }
     
     fclose(fsort);

     printf("All features had been loaded\n");
       
        for(i=0; i<TOTAL_TRAIN; i++)
     delete [] features[i];
     delete[] features;
}
 
Writing into a file is not a problem but when I try to retrieve it back only 750*84 out of 40000*84 samples can be retrieved.
Try to run this program. If any one can find any solution can you inform me as soon as possible.

Is it due to memory problem. 40000*84*4(float point data size is 4bytes)=13.44Mbyte. I have a 64Mbyte of SDRAM, Pentium 3 600Mhz and 14Gbyte of HDD.
ASKER CERTIFIED SOLUTION
Avatar of elcapitan
elcapitan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

alcapitan, you must have great eyes, or a much better font than I do!  :-)

Out of curiosity, was this posted as a comment or answer?
Thanks,
I posted it as comment

--EC--