🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #260

Re: The brother pointer gives me a headache

#260
From: Dann Corbit
Date: Mon, 16 Feb 1998 00:00
75 lines
3043 bytes
// I corrected most of the obvious syntax errors and programming errors.
// I have no idea if this is closer to what you are really after, but
// at least it won't fry memory. -- drc
// Your summation storage is way too small.  Use double at least, unless
// you want modular answers where the modulus is a mystery.
//
//      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 <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int             main()
{
    char            charin;
    long            counter;
    long            i;
    long           *num;
    long            sumnum;
    int             j;

    sumnum = 0;
    counter = 0;

    cout << "Wait..." << endl; // missing semicolon.  Flush with endl...
    // USE new[] NOT malloc() FOR C++ !!!
    // YOU WOULD PROBABLY HAVE AVOIDED THIS BLUNDER.
    if ((num = (long *) malloc(10000000 * sizeof(int))) == NULL) { //
sizeof...
        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) // I'm pretty sure you mean &&
                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;
}
--
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software?  Algorithms?  Pubs? http://www.infoseek.com
Technical Details
Message-ID: <6casd1$4s2$1@client2.news.psi.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <01bd3b40$c55acd50$a080fac3@johnpanoid>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,7b57483de3649335,start
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 108b44,7b57483de3649335,start
X-Google-Attributes: gid108b44,public
X-Google-Thread: 109fba,7b57483de3649335,start
X-Google-Attributes: gid109fba,public
From: "Dann Corbit" <dcorbit@solutionsiq.com>
Subject: Re: The brother pointer gives me a headache
Date: 1998/02/16
Message-ID: <6casd1$4s2$1@client2.news.psi.net>
X-Deja-AN: 325733903
Content-Transfer-Encoding: 7bit
References: <01bd3b40$c55acd50$a080fac3@johnpanoid>
Content-Type: text/plain; charset="iso-8859-1"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: SolutionsIQ
Mime-Version: 1.0
Newsgroups: att.lang.c++,comp.lang.c++,comp.sys.lang.c++