简体   繁体   中英

windows error running program in jGrasp

This code compiles with no errors but when I attempt to run it it gives a windows error that the "filename has stopped working". It lists no errors when I compile and link and no errors come up in the jGrasp program but windows comes up with an error box whenever I hit run. I do not know how to fix it any help you can give will be appreciated. Pls help

#include <math.h>
#include <stdio.h>
//FUNCTION PROTOTYPES=======================================================
// print report title and column headers
   void   printHeader( int month, int day );

// print game information report
   void   printGameInfo( int date[][2], int auscore[], int oppScore[],     double gameLen[],
                     int attend[], int numGames );

// open and read file into arrays return #games      
   int    getGameInfo( FILE* filePtr, int date[][2], int auScore[], int oppScore[],
                   double gameLen[], int attend[] );

// find the max of an integer array
   int    maxInt(int array[], int count);

// find the max of a double array
   double maxDouble(double array[], int count);  
//============================================================================  

int main  (){
#define MAXGAMES 15
#define year 2017
   int day,
   numGames,
   month;
   int date [MAXGAMES][2],
   auScore [MAXGAMES],
   oppScore [MAXGAMES],
   attend [MAXGAMES];
   double gameLen [MAXGAMES];
   FILE  *GAMEDATA;
   GAMEDATA = fopen ("seasonStats2017.txt","r");
   if (GAMEDATA == NULL )//bad open
      printf( "Error opening input file.");
   else //good open
      {//find and print last year's data

      numGames = getGameInfo( GAMEDATA, date, auScore, oppScore,
                        gameLen, attend );        

      printGameInfo( date, auScore, oppScore, gameLen,
                     attend, numGames );
      }
    return 0;
    }          

void   printHeader( int month, int day )
    {
      printf( "      \n%d AUBURN TIGERS", year);
      printf( "\n%d Auburn Games Results (as of %02d/%02d) \n", year, month,         day);
      printf("Date Score W-L Length Attend");
      printf("----- ----- --- ------ ------");
     }


int    getGameInfo( FILE* filePtr, int date[][2], int auScore[], int oppScore[],
                       double gameLen[], int attend[] )
{
   int k = 0,
       minutes[MAXGAMES],
       hours[MAXGAMES],
       day[MAXGAMES],
       month[MAXGAMES];

   while ( ( fscanf(filePtr,"%d", &month[k] ) ) == 1)
   {
      fscanf(filePtr,"%d", &day[k]);
      fscanf(filePtr,"%d", &auScore[k]);
      fscanf(filePtr,"%d", &oppScore[k]);
      fscanf(filePtr,"%d", &hours[k]);
      fscanf(filePtr,"%d", &minutes[k]);
      fscanf(filePtr,"%d", &attend[k]);
      date[k][0] = month[k];
      date[k][1] = day[k];
      gameLen[k] = hours[k] + (minutes[k]/60);
      k++;
   }
   return k-1;
}


double maxDouble(double array[], int count){
int i;
double highest = array[i]; 
   for(i = 0; i < count; i++) {
    if(highest<array[i])
          highest = array[i];
    }
    return highest;
}


int maxInt(int array[], int count){
int i;
   int highest = array[i]; 
   for(i = 0; i < count; i++) {
    if(highest<array[i])
          highest = array[i];
   }
   return highest;
}


void   printGameInfo( int date[][2], int auScore[], int oppScore[], double         gameLen[],
                     int attend[], int numGames ){
       int maxI,
       maxD,
       month,
       day,
       i;
       maxI = maxInt( attend, numGames);
       maxD = maxDouble( gameLen, numGames);
   month = date[numGames][0];
   day = date[numGames][1];
   printHeader(month, day );
   for (i=0; i<= numGames; i++)
   {
      printf ("  %02d/%02d %2d - %2d", date[i][0], date[i][1], auScore[i], oppScore[i]);
      if (auScore[i]>oppScore[i]){
      printf("W");
      }
      else{ printf("L");
      }
      printf (" %3.2lf   %5d ", gameLen[i],attend[i] );
   }

}

首先,开始添加打印语句,并弄清楚它崩溃的位置(或者它根本没有运行)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM