0

my problem is when I run my program it tells me that "Run-Time Check Failure #2 - Stack around the variable 'b1' was corrupted.If there is a handler for this exception, the program may be safely continued."

while (!feof(fp))
  {
   fscanf(fp, "%2X", &a1[0]);
   fscanf(fp, "%2X", &a1[1]);
   fscanf(fp, "%2X", &a1[2]);
   fscanf(fp, "%2X", &a1[3]);
   fscanf(fp, "%2X", &a1[4]);

   fscanf(fp, "%2X", &b1[0]);
   fscanf(fp, "%2X", &b1[1]);
   fscanf(fp, "%2X", &b1[2]);
   fscanf(fp, "%2X", &b1[3]);
   fscanf(fp, "%2X", &b1[4]);

   if (foo==foo)
   {
    foo....
   }
  }
  • What is b1? show the declaration. if (foo==foo); it is always true – Sreeraj Chundayil Jul 13 '15 at 09:19
  • @InQusitive `if (foo==foo); it is always true` Not necessarily. `foo` could be a `double` holding a `NaN` value, or an instance of a class with an unusual implementation of `operator==`. – Igor Tandetnik Jul 13 '15 at 14:28
  • If I had to guess: `a1` and `b1` are arrays of `char`; however, `%X` format specification expects a pointer to `int`. The program then exhibits undefined behavior. – Igor Tandetnik Jul 13 '15 at 14:29

0 Answers0