Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 23rd, 2011, 03:58 AM
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Error: Syntax Error or Access Violation codehappy VB How-To 7 October 3rd, 2007 05:41 PM
Error when running histogram in Analysis Toolkit xbenx Excel VBA 0 February 23rd, 2006 02:13 PM
Primary Key Violation error code hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 April 19th, 2005 07:41 PM
weird access violation Yosi Visual C++ 0 January 6th, 2005 05:19 AM
Access Violation ? T-5 Beginning PHP 1 July 24th, 2004 09:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.