Article View: att.lang.c++
Article #261The brother pointer gives me a headache
From: AlexV
Date: Tue, 17 Feb 1998 00:00
Date: Tue, 17 Feb 1998 00:00
67 lines
1785 bytes
1785 bytes
/*
Would you please tell me why am i getting an error message in VC:
Unhandled in MyArrayTest.exe 0x0000005: Access Violation
please look down to see where the error appears
*/
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <time.h>
int main() {
char charin;
long counter;
long i;
long *num;
long sumnum;
int j;
sumnum = 0;
counter = 0;
cout << "Wait..."
if ((num = (long *) malloc(10000000)) == NULL)
{
printf("Not enough memory to allocate buffer\n");
cin >> counter;
exit(1);
}
j = 0;
for (i = 0; i < 10000000; i++ ) {
if ( i % 100 == 0 ){
*(num + i) = 38;
}
else {
/************** HERE IT IS ************/
*(num + i) = 50; // it gives me an errors when i = 2119943
/************* END HERE IT IS ********/
if ( i > 2299000 & i < 2320000)
cout << i << "\n";
}
}
cout << "Finished putting values in memory,\n\n Press enter to calculate
the average: ";
cin >> charin;
counter = 0;
for (i = 0; i < 10000000; i++ ) {
sumnum = sumnum + *(num + i);
counter++;
}
free(num);
cout << "\n\n\nAverage is " << sumnum / i;
cin >> charin;
return 0;
}
Technical Details
Message-ID:
<01bd3b40$c55acd50$a080fac3@johnpanoid>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,7b57483de3649335 X-Google-Attributes: gid10d4ba,public X-Google-Thread: 109fba,7b57483de3649335 X-Google-Attributes: gid109fba,public X-Google-Thread: 108b44,7b57483de3649335 X-Google-Attributes: gid108b44,public From: "AlexV" <alexvak@hotmail.com> Subject: The brother pointer gives me a headache Date: 1998/02/17 Message-ID: <01bd3b40$c55acd50$a080fac3@johnpanoid> X-Deja-AN: 325725283 Organization: . Newsgroups: att.lang.c++,comp.lang.c++,comp.sys.lang.c++