-5

I have done a bit of a research online but did not find an explanation for the error code -1073741676, displayed by Code::Blocks.

The exact error message is Process terminated with status -1073741676 (0 minute(s), 8 second(s)).

Is there a global, constant explanation for this precise status, or does it change with compiler, IDE or any other variable?

Code (as Minimal as I could) :

main.cpp

    int n(0), choix(0);
    string dis;
    // Nobel* laureats = saisie(n); // Saisie à la main

    Nobel* laureats = lecture(n);
    cin >> dis;
    cout << agemoyen(laureats, n, dis) << endl;

Nobel.h

#ifndef NOBEL_H_INCLUDED
#define NOBEL_H_INCLUDED

#include <string>


struct Nobel
{
    std::string nom, discipline;
    int annee, age;
    std::string pays;
};
int agemoyen(Nobel* NO, int n, std::string dis);
Nobel* lecture(int& n);

#endif // NOBEL_H_INCLUDED

Nobel.cpp

int agemoyen(Nobel* NO, int n, string dis){
    int ages(0);
    int total(0);

     for(int i = 0 ; i < n ; i++){
        if(NO[i].discipline == dis){
            ages += NO[i].age;
            total++;
        }
    }
    ages /= total;

    return ages;
}

Nobel* lecture(int& n){
    Nobel* laureats;

    ifstream fichier("tp7nobel.txt", ios::in);

    if (fichier.is_open()) {
        fichier >> n;

        cout << n << endl;
        laureats = new Nobel[n];

        for(int i = 0 ; i < n; i++){
            fichier >> laureats[i].nom >> laureats[i].discipline >> laureats[i].annee >> laureats[i].age >> laureats[i].pays;
            cout << i << ")" << laureats[i]. nom << endl;
        }
        fichier.close();
    }else{
        cerr << "Impossible d'ouvrir ce fichier." << endl;
    }

    return laureats;
}

1 Answers1

4

-1073741676 is the hex value 0xC0000094 - Integer division by zero exception code on Windows

Code: c0000094 Description: EXCEPTION_INT_DIVIDE_BY_ZERO

UPDATE I suppose you have to check whether total is not zero before using it:

if (total) {
    ages /= total;
}
Mihayl
  • 3,821
  • 2
  • 13
  • 32
  • Thanks for the answer. Another part of my question is: is this status code constant over different compiler to describe a divison by zero exception? –  Nov 21 '17 at 21:35
  • 1
    No, this is Windows specific. On Linux I think you get a signal SIGFPE, I think. See https://stackoverflow.com/a/3105604/8918119 But you do not need to do it. It should't happen in the first place. – Mihayl Nov 21 '17 at 21:36
  • @AA Thank you very much then for both answers! The issue is indeed solved when making sure total is not equal to zero. Beginners' error, I guess! –  Nov 21 '17 at 21:38
  • @absolutelyLost one thing to take away from this is when you are given a number and you don't recognize any significance to it, convert it it hexadecimal and see if it makes more sense. Another one you'll see often is 3452816845 or -842150451 (a bunch of CDCD denoting uninitialized memory. – user4581301 Nov 21 '17 at 22:42