Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-06-24
3
Medium Priority
?
193 Views
Last Modified: 2010-04-02
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.
0
Comment
Question by:tiagrajah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
elcapitan earned 90 total points
ID: 6223509
You have access violation.
Replace the line: fscanf(fsort,"%f",&features[j][i]);
with the line: fscanf(fsort,"%f",&features[i][j]);

--EC--
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224264
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?
0
 
LVL 3

Expert Comment

by:elcapitan
ID: 6224286
Thanks,
I posted it as comment

--EC--
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question