Home c raw exception at 0x60A9B49C (MSVCR110D.DLL)

raw exception at 0x60A9B49C (MSVCR110D.DLL)

Author

Date

Category

Tell me, please have an error related to associated with:

Raw exception to 0x51F8B49C (msvcr110d.dll) in Project2.exe: 0xc0000005: Violation of access rights when recording at 0xCCCCCCC.

Listing code:

# include & lt; stdio.h & gt;
# INCLUDE & LT; String.h & gt;
# INCLUDE & LT; Conio.h & gt;
# INCLUDE & LT; CLOCALE & GT;
# INCLUDE & LT; Windows.h & GT;
STRUCT STUDENT {
  CHAR FIO [21];
  int grup;
  INT OC1;
  INT OC2;
  INT OC3;
  INT OC4;
  BOOL ZACH1;
  BOOL ZACH2;
  BOOL ZACH3;
  BOOL ZACH4;
  BOOL ZACH5;
};
Void Neusst (Int K, Student * MS);
Void SrBal (Int K, Student * MS);
INT MAIN ()
{
  SetLocale (LC_CTYPE, "RUSSIAN");
  int i;
  File * f;
  STRUCT STUDENT MS [300];
  if ((F = Fopen ("Students.txt", "R")) == NULL)
    Puts ("File not found.");
  For (i = 0;! FeeF (F); I ++) {
    FGETS (MS [i] .fio, 15, F);
    FSCANF (F, "% d% d% d% d% d% d% d% d% d% d", MS [I] .Grup, MS [I] .OC1, MS [I] .OC2, MS [ i] .oc3, MS [I] .OC4, MS [i] .Zach1, MS [i] .zach2, MS [i] .zach3, MS [i] .zach4, MS [i] .zach5);
  }
  int k = i; // number of the last read element of the array M
  Char C;
  do {
    System ("CLS"); // notice on clrscr (); for compilers not visualstudio
    // CLRSRC ();
    Puts ("==========================================");
    Puts ("Select Action:");
    Puts ("1-show no sense students");
    Puts ("2-identify the average score of one of the groups");
    c = getchar ();
    Switch (C) {
    Case 1:
      Neusst (k, MS);
      Break;
    Case 2:
      SRBAL (K, MS);
      Break;
    }
    getchar ();
  } while (C = '4');
}
Void Neusst (Int K, Student * MS)
{
  For (int i = 0; i & lt; = k; i ++) {
    int zad = 0;
    BOOL NET = 0;
    IF (MS [I] .OC1 == 0)
      ZAD ++;
    IF (MS [I] .OC2 == 0)
      ZAD ++;
    IF (MS [I] .OC3 == 0)
      ZAD ++;
    IF (MS [I] .OC4 == 0)
      ZAD ++;
    IF (MS [i] .zach1 == 0)
      ZAD ++;
    IF (MS [i] .zach2 == 0)
      ZAD ++;
    if (MS [i] .Zach3 == 0)
      ZAD ++;
    if (MS [i] .zach4 == 0)
      ZAD ++;
    IF (MS [i] .zach5 == 0)
      ZAD ++;
    if (zad & gt; 0) {
      Printf ("% s group No.% D has -% D deblia", MS [I] .FIO, MS [I] .Grup, ZAD);
      NET = 1;
    }
    if (net == 0)
      Puts ("There are no bad students in the group");
  }
  Puts ("To return to the menu, press any key ...");
  getchar ();
}
Void Srbal (Int K, Student * MS)
{
  Puts ("Enter the group number:");
  int nomer;
  Float SRSTUD [30];
  int kolvo = 0;
  Float OcGrup = 0;
  Scanf ("% d", & amp; nomer);
  For (int i = 0; i & lt; = k; i ++) {
    if (nomer = MS [i] .Grup)
      SRStud [i] = (MS [i] .oc1 + MS [i] .oc2 + MS [i] .oc3 + MS [i] .oc4) / 4;
    PrintF ("% s Average rating - 1.% F", MS [I] .FIO, SRStud [i]);
    kolvo ++;
    OCGRUP = OCGRUP + SRSTUD [I];
  }
  float srocgrup = ocgrup / kolvo;
  PrintF ("Middle Score Group as a whole -% d", srocgrup);
  Puts ("To return to the menu, press any key ...");
  getchar ();
}

I wrote the code here to this task.

Dan file containing information about the delivery of the session. File recording structure: student name, group number; Estimates for four exams and five credits;

  1. Write a program issuing surnames of poor students with indication of group numbers and the amount of debts
  2. Determination of the middle score obtained by each student of the group X and the entire group as a whole.

    File Contents for Students.txt

    Tests

& gt; Barabanov A.A. 1233 5 5 5 5 1 1 1 1 0
  & gt; Balalaykin V.V. 1233 4 2 4 0 0 0 0 1 0
  & gt; Burundukov A.D. 3122 3 2 5 5 1 0 0 0 1
  & gt; Bandurin TD 2423 5 3 4 5 1 1 1 1 1

Answer 1, Authority 100%

@Carpoff , looked a little more closely. As they say, “Elementary, my dear Watson.”

First in the fscanf ()

fscanf (f, "% d% d% d% d% d% d% d% d% d% d ", ms [i] .grup, ms [i] .oc1, ms [i] .oc2, ms [i] .oc3, ms [i] .oc4, ms [i] .zach1, ms [i]. zach2, ms [i] .zach3, ms [i] .zach4, ms [i] .zach5);

Naturally it is necessary to transmit the address field structure. Ie.

fscanf (f, "% d% d% d% d% d% d% d% d% d% d ", & amp; ms [i] .grup, & amp; ms [i] .oc1, & amp; ms [i] .oc2, & amp; ms [i] .oc3, & amp; ms [i] .oc4, & amp; ms [i] .zach1, & amp; ms [i] .zach2, & amp; ms [i] .zach3, & amp; ms [i] .zach4, & amp; ms [i] .zach5);

But with the second (surname reading) difficult. Yes, you read the first 14 characters in ms [i] .fio, but only to the first line This works because after the fscanf () for the first line in it will ‘\ n’, which reads fgets () on the second iteration, and then fscanf () instead of numbers will receive a letter and all (will not work).

point O. after the fscanf () is necessary to read the end of the line (do again fgets () in any buffer or in a loop to read fgetc () to ‘\ n’).

In general, the rigid format (the number after the 15th position) – it is somehow ugly. Try to read the name as something else, for example to the first digit. Then it (figure) can be brought back into the stream causing ungetc ().


Answer 2

0xCCCCCCCC – uninitialized address, look where this comes all the falls. The debugger variable pointer contains this value, but it is not clear where it came from in the code.

Next, you can definitely say, falls to “Select an action” or after. Just see if ms out [i] array abroad, and it is better to make the check.

You can attach a file to the student data that it could test the software.


Answer 3

It is likely that the problem in this line

for (int i = 0; i & lt; = k; i ++) {

the condition you want to change on the i & lt; k

Condition

for (i = 0;! Feof (f); i ++) {

need to improve

for (i = 0;! Feof (f) || i & gt; = 299; i ++) {

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions