View Single Post
  #1 (permalink)  
Old September 23rd, 2011, 03:58 AM
lina lina is offline
Registered User
 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Histogram code has any Error:Access violation reading location

Dear All,

I need your help, I'll create a frequency histogram from 1000 array in txt file. But I've some error with my code (message error: Access violation reading location) . I've no idea to solved it.. Please help me, I'm very thanks for the help..


#include <fstream>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#define MAXVAL 1000
#define COUNTER 11
using namespace std;


int readData(char *filepath, float *data, int nReadLength)
{
ifstream load(filepath);

if(!load.good()) return 0;

int count=0;

while(!load.eof() && count<nReadLength)
{
load >> data[count];
count++;
}

load.close();

return count;
}

int writeData(char *filepath, float *data, int length)
{
ofstream save(filepath);

if(!save.good()) return 0;

for(int i=0 ; i<length ; i++)
save << data[i] << endl;

save.close();

return 1;
}

float histogram(float *data, int length)


{ float histo;
int i,j, low, high;
float group[COUNTER] = {0,0,0,0,0,0,0,0,0,0,0};
for(j=1;j<=length;j++)
{
++ group[ (int) ( data[j] + 0.005 ) / 10] ;

/*Unhandled exception at 0x00a622cc in mean.exe: 0xC0000005: Access violation reading location 0xfda19e6c */
}

printf("\n");
printf(" GROUP RANGE FREQUENCY\n\n") ;
for( i = 0 ; i < COUNTER ; i++ )
{
low = i * 0.1 ;
if(i == 10)
high = 1 ;
else
high = low + 0.09 ;
printf(" %2d %f to %f %d\n",
i+1, low, high, group[i] ) ;
}

return histo;
}

void main()
{ float histo = 0;
float signal[1000];
readData("D:\\Signal D.txt", signal, 1000);
histo = histogram(signal,1000);
writeData("D:\\Histogram D.txt",signal, 1000);
//meanval[1] = mean(signal, 9);
}
Reply With Quote